using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;
using Lucee.WebBase.Utils;
using Lucee.WebBase.Data;
using System.Drawing;
using Emgu.CV;
using Emgu.CV.Util;
using Emgu.CV.Structure;
using System.Drawing.Drawing2D;
using System.Net;
using Newtonsoft;
using Newtonsoft.Json.Converters;
using Newtonsoft.Json;
using System.Web.Script.Serialization;
using MySql.Data.MySqlClient;
using Emgu.CV.Flann;
using System.Data.SqlTypes;
using System.Security.AccessControl;
using System.Security.Cryptography;
using Microsoft.SqlServer.Server;
public partial class Temp_UserNoPostionTemp : System.Web.UI.Page
{
public long TempID = 0;
public long AnotherTempID = 0;
public string PageIndex = "0";
public string Bindlist = "";
public string imgage = "";
public string ExamNO = "";
public string isLocked = "";
public string HideAreaText = "";
public string IsPostionValue = "";
public long tenant = 0;
public string pager = "";
public int isHand = 0;
public string MainTempId = "0";
public int PageCount = 0;
public string UserID = "";
public string Rotate = "";
public string BatchID = "";
public string GroupNo = "";
public string ishaspostion = "";
protected void Page_Load(object sender, EventArgs e)
{
int action = Globals.Request("action") == "" ? 0 : Convert.ToInt32(Globals.Request("action"));
tenant = Globals.Request("tenant") == "" ? 0 : Convert.ToInt64(Globals.Request("tenant"));
isHand = Globals.Request("isHand") == "" ? 0 : Convert.ToInt32(Globals.Request("isHand"));
BatchID = Globals.Request("BatchID");
pager = Globals.Request("pager").ToLower();
GroupNo = Globals.Request("GroupNo");
ishaspostion = Globals.Request("ishaspostion");
if (action != 0)
{
Response.Clear();
switch (action)
{
case 1:
UpdateTempData();
break;
case 2:
LockTemp();
break;
}
Response.End();
}
else
{
TempID = Globals.Request("TempID") == "" ? 0 : Convert.ToInt32(Globals.Request("TempID"));//获取小模板ID
//if (TempID == 0)
//{
// Response.Write("");
// return;
//}
UserID = Globals.Decrypt(Globals.Request("UserID"));
if (string.IsNullOrEmpty(UserID))
{
Response.Write("");
return;
}
string sql = "";
sql = "select * from MK_TempleteDataUser where DetaID_bigint=" + TempID + " AND UserID_bigint=" + UserID;
if (!string.IsNullOrEmpty(GroupNo))
{
sql = "select * from MK_TempleteDataUserOnePaper where DetaID_bigint=" + TempID + " AND GroupNo_varchar='" + GroupNo + "'";
}
if (!string.IsNullOrEmpty(BatchID))
{
sql = "select * from MK_TempleteDataUserBatch where DetaID_bigint=" + TempID + " AND BatchID_nvarchar='" + BatchID + "'";
}
// string sql = "select * from MK_TempleteData where ID_bigint=" + TempID;
DataTable dtx = new MysqlDBHelper(tenant).ExecuteQuery(sql);
if (dtx.Rows.Count > 0)
{
Bindlist = dtx.Rows[0]["TempValue_nvarchar"].ToString();
imgage = dtx.Rows[0]["TempPicture64_nvarchar"].ToString();
//isLocked = dtx.Rows[0]["islock_bit"] == null ? "" : dtx.Rows[0]["islock_bit"].ToString();
HideAreaText = dtx.Rows[0]["HideAreaPostionList_nvarchar"] == null ? "" : dtx.Rows[0]["HideAreaPostionList_nvarchar"].ToString();
//IsPostionValue = dtx.Rows[0]["HideAreaPostionList_nvarchar"] == null ? "" : dtx.Rows[0]["HideAreaPostionList_nvarchar"].ToString();
Rotate = dtx.Rows[0]["Rotate_float"].ToString();
PageIndex = dtx.Rows[0]["PageIndex_int"] == null ? "" : dtx.Rows[0]["PageIndex_int"].ToString();
MainTempId = dtx.Rows[0]["MainID_bigint"].ToString();
sql = "select MainPage_int,HasPosition from MK_TempleteMain where ID_bigint=" + MainTempId;
var maindt = new MysqlDBHelper(tenant).ExecuteQuery(sql);
if (maindt == null || maindt.Rows.Count <= 0)
{
Response.Write("");
return;
}
PageCount = Convert.ToInt32(maindt.Rows[0]["MainPage_int"]);
IsPostionValue = maindt.Rows[0]["HasPosition"].ToString();
if (PageCount > 1)
{
sql = "select ID_bigint from MK_TempleteData where MainID_bigint=" + MainTempId + " and ID_bigint!=" + TempID;
AnotherTempID = Convert.ToInt32(new MysqlDBHelper(tenant).ExecuteScalar(sql));
}
}
}
}
private void UpdateTempData()
{
TempID = Globals.Request("TempID") == "" ? 0 : Convert.ToInt32(Globals.Request("TempID"));//获取小模板ID
string totalHtml = Server.UrlDecode(Globals.Request("totalHtml"));
string HideAreaPostionList = Server.UrlDecode(Globals.Request("HideAreaPostionList"));
string UserID = Globals.Request("UserID");
double roteX = Convert.ToDouble(Globals.Request("roteX"));
string BatchID = Globals.Request("BatchID");
string GroupNo = Globals.Request("GroupNo");
if (AnsyTemp(HideAreaPostionList, totalHtml, UserID))
{
//string sql = "Update MK_TempleteData SET TempValue_nvarchar=@TempValue_nvarchar,HideAreaPostionList_nvarchar=@HideAreaPostionList_nvarchar where ID_bigint=" + TempID;
//MySqlParameter[] sp = new MySqlParameter[] {
// new MySqlParameter("@TempValue_nvarchar",totalHtml),
// new MySqlParameter("@HideAreaPostionList_nvarchar",HideAreaPostionList)
//};
//string[] totalHtmlList = totalHtml.Split('$');
//new MysqlDBHelper(tenant).ExecuteNoQuery(sql, sp);
string sql = "";
MySqlParameter[] sp;
if (BatchID != "")
{
sql = "Update MK_TempleteDataUserBatch SET Rotate_float=@Rotate_float, TempValue_nvarchar=@TempValue_nvarchar,HideAreaPostionList_nvarchar=@HideAreaPostionList_nvarchar,islocked_int=1 where DetaID_bigint=" + TempID + " AND BatchID_nvarchar='" + BatchID + "'";
sp = new MySqlParameter[] {
new MySqlParameter("@TempValue_nvarchar",totalHtml),
new MySqlParameter("@HideAreaPostionList_nvarchar",HideAreaPostionList),
new MySqlParameter("@Rotate_float",roteX)
};
}
else if (GroupNo != "")
{
sql = "Update MK_TempleteDataUserOnePaper SET Rotate_float=@Rotate_float, TempValue_nvarchar=@TempValue_nvarchar,HideAreaPostionList_nvarchar=@HideAreaPostionList_nvarchar,islocked_int=1 where DetaID_bigint=" + TempID + " AND GroupNo_varchar='" + GroupNo + "'";
sp = new MySqlParameter[] {
new MySqlParameter("@TempValue_nvarchar",totalHtml),
new MySqlParameter("@HideAreaPostionList_nvarchar",HideAreaPostionList),
new MySqlParameter("@Rotate_float",roteX)
};
}
else
{
sql = "Update MK_TempleteDataUser SET Rotate_float=@Rotate_float, TempValue_nvarchar=@TempValue_nvarchar,HideAreaPostionList_nvarchar=@HideAreaPostionList_nvarchar,islocked_int=1 where DetaID_bigint=" + TempID + " AND UserID_bigint=" + Convert.ToInt64(UserID);
sp = new MySqlParameter[] {
new MySqlParameter("@TempValue_nvarchar",totalHtml),
new MySqlParameter("@HideAreaPostionList_nvarchar",HideAreaPostionList),
new MySqlParameter("@Rotate_float",roteX)
};
}
if (new MysqlDBHelper(tenant).ExecuteNoQuery(sql, sp) == 1)
{
Response.Write("ok");
}
else
{
Response.Write("erro");
}
}
//if (new MysqlDBHelper(tenant).ExecuteNoQuery(sql, sp) == 1)
//{
// if (totalHtmlList[0] == "")
// {
// Response.Write("ok");
// }
// else
// {
// AnsyTemp(HideAreaPostionList);
// }
//}
//else {
// Response.Write("0");
//}
}
private void LockTemp()
{
TempID = Globals.Request("TempID") == "" ? 0 : Convert.ToInt32(Globals.Request("TempID"));//获取小模板ID
string totalHtml = Server.UrlDecode(Globals.Request("totalHtml"));
string HideAreaPostionList = Server.UrlDecode(Globals.Request("HideAreaPostionList"));
string[] totalHtmlList = totalHtml.Split('$');
string userID = Globals.Request("userID");
if (AnsyTemp(HideAreaPostionList, totalHtml, userID))
{
string sql = "Update MK_TempleteData SET TempValue_nvarchar=@TempValue_nvarchar,HideAreaPostionList_nvarchar=@HideAreaPostionList_nvarchar,islock_bit=1 where ID_bigint=" + TempID;
MySqlParameter[] sp = new MySqlParameter[] {
new MySqlParameter("@TempValue_nvarchar",totalHtml),
new MySqlParameter("@HideAreaPostionList_nvarchar",HideAreaPostionList)
};
AddQuestionData(totalHtml);
new MysqlDBHelper(tenant).ExecuteNoQuery(sql, sp);
}
//if (new MysqlDBHelper(tenant).ExecuteNoQuery(sql, sp) == 1)
//{
// if (totalHtmlList[0] == "")
// {
// Response.Write("ok");
// }
// else {
// AnsyTemp(HideAreaPostionList);
// }
//}
//else
//{
// Response.Write("0");
//}
}
private void AddQuestionData(string totalHtml)
{
TempID = Convert.ToInt64(Globals.Request("TempID"));
string[] totalHtmlList = totalHtml.Split('$');
string kg = totalHtmlList[2];
string zg = totalHtmlList[3];
string[] questionlist = kg.Trim('^').Split('^');
string[] zglist = zg.Trim('^').Split('^');
string sql = "";
if (kg != "")
{
for (int i = 0; i < questionlist.Length; i++)
{
string[] detailtList = questionlist[i].Split(',');
string starNum = detailtList[4].ToUpper();
string endNum = detailtList[5].ToUpper();
string score = detailtList[9];
if (score == "")
{
score = "0";
}
string selectNum = detailtList[6];
string isselectmore = detailtList[8];
string bigNum = "";
if (starNum.Contains("M"))
{
bigNum = starNum.Split('M')[0];
int startSmallNum = Convert.ToInt32(starNum.Split('M')[1]);
int endSmallNum = Convert.ToInt32(endNum.Split('M')[1]);
for (int j = Convert.ToInt32(startSmallNum); j <= Convert.ToInt32(endSmallNum); j++)
{
sql = "SELECT COUNT(1) FROM MK_TempQuestionData WHERE TempID_bigint=" + TempID + " AND QuestionIndex_int='" + (bigNum + "." + j) + "'";
if (new MysqlDBHelper(tenant).ExecuteScalar(sql).ToString() == "0")
{
sql = "INSERT INTO MK_TempQuestionData(TempID_bigint,QuestionIndex_int,SmallQuestionDetail_nvarchar,Score_float,createdtime_datetime,smallQuestionNum_int,questiontype_int,selectNum_int,selecttype_int) VALUES(@TempID_bigint,@QuestionIndex_int,@SmallQuestionDetail_nvarchar,@Score_float,'" + DateTime.Now + "',@smallQuestionNum_int,0,@selectNum_int,@selecttype_int)";
MySqlParameter[] sp = new MySqlParameter[] {
new MySqlParameter("@TempID_bigint",TempID),
new MySqlParameter("@QuestionIndex_int",bigNum+"."+j),
new MySqlParameter("@SmallQuestionDetail_nvarchar",""),
new MySqlParameter("@smallQuestionNum_int","1"),
new MySqlParameter("@Score_float",score),
new MySqlParameter("@selectNum_int",selectNum),
new MySqlParameter("@selecttype_int",isselectmore),
};
new MysqlDBHelper(tenant).ExecuteNoQuery(sql, sp);
}
}
}
else
{
for (int j = Convert.ToInt32(starNum); j <= Convert.ToInt32(endNum); j++)
{
sql = "SELECT COUNT(1) FROM MK_TempQuestionData WHERE TempID_bigint=" + TempID + " AND QuestionIndex_int='" + j + "'";
if (new MysqlDBHelper(tenant).ExecuteScalar(sql).ToString() == "0")
{
sql = "INSERT INTO MK_TempQuestionData(TempID_bigint,QuestionIndex_int,SmallQuestionDetail_nvarchar,Score_float,createdtime_datetime,smallQuestionNum_int,questiontype_int,selectNum_int,selecttype_int) VALUES(@TempID_bigint,@QuestionIndex_int,@SmallQuestionDetail_nvarchar,@Score_float,'" + DateTime.Now + "',@smallQuestionNum_int,0,@selectNum_int,@selecttype_int)";
MySqlParameter[] sp = new MySqlParameter[] {
new MySqlParameter("@TempID_bigint",TempID),
new MySqlParameter("@QuestionIndex_int",j),
new MySqlParameter("@SmallQuestionDetail_nvarchar",""),
new MySqlParameter("@smallQuestionNum_int","1"),
new MySqlParameter("@Score_float",score),
new MySqlParameter("@isSelectMore_bit",isselectmore),
new MySqlParameter("@selectNum_int",selectNum),
new MySqlParameter("@selecttype_int",isselectmore),
};
new MysqlDBHelper(tenant).ExecuteNoQuery(sql, sp);
}
}
}
}
}
if (zg != "")
{
for (int i = 0; i < zglist.Length; i++)
{
string[] detailtList = zglist[i].Split(',');
bool issplit = false;
if (detailtList[4].Contains("X"))
{
issplit = true;
detailtList[4] = detailtList[4].Split('X')[0];
}
//sql = "SELECT COUNT(1) FROM MK_TempQuestionData WHERE TempID_bigint=" + TempID + " AND QuestionIndex_int='" + detailtList[4] + "'";
sql = String.Format("SELECT COUNT(1) FROM MK_TempQuestionData where TempID_bigint in(select ID_bigint from MK_TempleteData where MainID_bigint =(SELECT MainID_bigint FROM " +
"`MK_TempleteData` where ID_bigint={0})) AND QuestionIndex_int='{1}';", TempID, detailtList[4]);
string mkscoretype = "";
if (string.IsNullOrEmpty(detailtList[7]))
{
mkscoretype = "1";
}
else
{
mkscoretype = detailtList[7];
}
if (new MysqlDBHelper(tenant).ExecuteScalar(sql).ToString() == "0")
{
sql = "INSERT INTO MK_TempQuestionData(TempID_bigint,QuestionIndex_int,SmallQuestionDetail_nvarchar,Score_float,createdtime_datetime,smallQuestionNum_int,questiontype_int,mkscoretype_float,is_split) VALUES(@TempID_bigint,@QuestionIndex_int,@SmallQuestionDetail_nvarchar,@Score_float,'" + DateTime.Now + "',@smallQuestionNum_int,1,@mkscoretype_float,@is_split)";
MySqlParameter[] sp = new MySqlParameter[] {
new MySqlParameter("@TempID_bigint",TempID),
new MySqlParameter("@QuestionIndex_int",detailtList[4]),
new MySqlParameter("@SmallQuestionDetail_nvarchar",""),
new MySqlParameter("@Score_float",detailtList[6]==""? "0" : detailtList[6]),
new MySqlParameter("@smallQuestionNum_int",detailtList[5]),
new MySqlParameter("@mkscoretype_float",mkscoretype),
new MySqlParameter("@is_split",issplit)
};
new MysqlDBHelper(tenant).ExecuteNoQuery(sql, sp);
}
}
}
}
///
/// 锁定模板数据
///
public bool AnsyTemp(string HideAreaPostionList, string totalHtml, string UserID)
{
try
{
CommonUse commonUse = new CommonUse();
string BatchID = Globals.Request("BatchID");
string GroupNo = Globals.Request("GroupNo");
long TempID = Convert.ToInt64(Globals.Request("TempID"));
string sql = "select * from MK_TempleteDataUser where DetaID_bigint=" + TempID + " AND UserID_bigint=" + UserID;
if (BatchID != "")
{
sql = @"select * from MK_TempleteDataUserBatch where DetaID_bigint=" + TempID + " AND BatchID_nvarchar='" + BatchID + "'";
}
else if (GroupNo != "")
{
sql = @"select * from MK_TempleteDataUserOnePaper where DetaID_bigint=" + TempID + " AND GroupNo_varchar='" + GroupNo + "'";
}
DataTable dt = new MysqlDBHelper(tenant).ExecuteQuery(sql);
if (dt.Rows.Count <= 0)
{
Response.Write("NO DATA");
return false;
}
//Bitmap PictureBoxBitMap = ImgGet(dt.Rows[0]["TempPicture64_nvarchar"].ToString());
////var PictureBoxBitMap = commonUse.RotateByOrientation(tempPictureBoxBitMap);
//if (PictureBoxBitMap == null)
//{
// Response.Write("NO PICTURE");
//}
//string[] GetData = totalHtml.Split('$');
//string PYPostionList = "";
//int width = Convert.ToInt32(GetData[6].Split(',')[0]);
//int height = Convert.ToInt32(GetData[6].Split(',')[1]);
//PictureBoxBitMap = ScaleToSize(PictureBoxBitMap, width, height);
//Image imagex = new Image(PictureBoxBitMap);
//Mat mat_threshold1 = new Mat();
//CvInvoke.Threshold(imagex, mat_threshold1, 160, 255, Emgu.CV.CvEnum.ThresholdType.BinaryInv);
//Mat mat_dilate1 = commonUse.MyDilate(mat_threshold1);
//VectorOfVectorOfPoint selected_contours1;
//selected_contours1 = commonUse.GetUsefulContoursDingWei(mat_dilate1, 1);
//Image currentFramext = new Image(PictureBoxBitMap);
//int PageIndex = Convert.ToInt32(Globals.Request("PageIndex"));
//if (PageIndex == 1)
//{
// int mx = GetOtherBitmaplist(currentFramext.Mat, 160, PYPostionList.Split(','), GetData[9]);
// long MainTempId = Convert.ToInt64(Globals.Request("MainTempId"));
// if (mx == 0)
// {
// Response.Write("标准点数据错误,请重新框选");
// return false;
// }
//}
//计算模板图片参数
//double xielv = 0;
//width = Convert.ToInt32(GetData[6].Split(',')[0]);
//height = Convert.ToInt32(GetData[6].Split(',')[1]);
//sql = "UPDATE MK_TempleteData SET XieLv_float =@XieLv_float,CutWidth_int=@CutWidth_int,CutHeight_int=@CutHeight_int,PyPPostion_nvarchar=@PyPPostion_nvarchar WHERE ID_bigint=" + TempID;
//MySqlParameter[] sp = new MySqlParameter[] {
// new MySqlParameter("@XieLv_float",xielv),
// new MySqlParameter("@CutWidth_int",width),
// new MySqlParameter("@CutHeight_int",height),
// new MySqlParameter("@PyPPostion_nvarchar",PYPostionList)
// };
//if (new MysqlDBHelper(tenant).ExecuteNoQuery(sql, sp) > 0)
//{
//}
//PictureBoxBitMap.Dispose();
return true;
}
catch (Exception ex)
{
return false;
Response.Write("TEMPERRO");
}
}
///
/// 获取其他截图
///
///
///
///
///
///
///
public static int GetOtherBitmaplist(Mat color_mat, int Threshold, string[] PYPostion, string postiontiaomaX)
{
CommonUse commonUse = new CommonUse();
string[] quekao = postiontiaomaX.Split(',');
//int X = Convert.ToInt32(Convert.ToDouble(quekao[0])) - Convert.ToInt32(PYPostion[0]);
//int Y = Convert.ToInt32(Convert.ToDouble(quekao[1])) - Convert.ToInt32(PYPostion[1]);
int X = Convert.ToInt32(Convert.ToDouble(quekao[0]));
int Y = Convert.ToInt32(Convert.ToDouble(quekao[1]));
int W = Convert.ToInt32(Convert.ToDouble(quekao[2]));
int H = Convert.ToInt32(Convert.ToDouble(quekao[3]));
int xuanXiang = 1;//选项数量
int tiliang = 1;//题量
string mx = "";
int wL = Convert.ToInt32(W / xuanXiang);
int hL = Convert.ToInt32(H / tiliang);
Image bytimg = GetMatCutImg(color_mat.Bitmap, X, Y, W, H);
X = 0; Y = 0;
Mat src = bytimg.Mat;
Mat mat_threshold = new Mat();
CvInvoke.Threshold(src, mat_threshold, Threshold, 254, Emgu.CV.CvEnum.ThresholdType.BinaryInv);
Mat mat_dilate = commonUse.MyDilate(mat_threshold);
VectorOfVectorOfPoint selected_contours;
int option_pixel_options = 0;
selected_contours = GetUsefulContoursSelectoOptionQK(mat_dilate, 1, out option_pixel_options);
mx = GetValueAndDrawGrid_Other(src.Bitmap, selected_contours, X, wL, xuanXiang, Y, hL, tiliang, "");
bytimg.Dispose();
src.Dispose();
return option_pixel_options;
}
///
/// 筛选图中符合给定条件的轮廓
///
/// 要提取轮廓的图片
/// 轮廓外接矩形大于该宽度值
/// 轮廓外接矩形小于该宽度值
/// 轮廓外接矩形大于该高度值
/// 轮廓外接矩形小于该高度值
public static VectorOfVectorOfPoint GetUsefulContoursSelectoOptionQK(Mat mat, double ratio, out int option_pixel_options)
{
option_pixel_options = 0;
VectorOfVectorOfPoint contours = new VectorOfVectorOfPoint();//所有的轮廓
VectorOfVectorOfPoint selected_contours = new VectorOfVectorOfPoint();//用于存储筛选过后的轮廓
CvInvoke.FindContours(mat, contours, null, Emgu.CV.CvEnum.RetrType.External,
Emgu.CV.CvEnum.ChainApproxMethod.ChainApproxSimple);//提取所有轮廓,操作过程中会对输入图像进行修改
//筛选轮廓。筛选条件:长宽比大于给定值
for (int i = 0; i < contours.Size; i++)
{
Rectangle rect = CvInvoke.BoundingRectangle(contours[i]);//外接矩形
Mat temp = new Mat(mat, rect);//提取ROI矩形区域
int pxNums = CvInvoke.CountNonZero(temp);//计算图像内非零像素个数
double area = CvInvoke.ContourArea(contours[i]);//计算连通轮廓的面积
double length = CvInvoke.ArcLength(contours[i], false); //计算连通轮廓的周长
VectorOfPoint approx_curve = new VectorOfPoint();//用于存放逼近的结果
CvInvoke.ApproxPolyDP(contours[i], approx_curve, length * 0.02, true);
//bool bo = (area > 500 && area < 12000);//&& rect.Height<100
//bool bo = ((area > 20 && area < 150000) && rect.Height > 8 );
bool bo = ((area > 10 && area < 150000) && rect.Height > 5);
if (bo)
{
if (pxNums > (area * 0.7))
{
option_pixel_options = pxNums;
selected_contours.Push(contours[i]);
}
}
}
return selected_contours;
}
///
/// 画出网格并返回填图结果
///
///
///
/// 左边距
/// 方块长度
/// 方块数量
/// 上边距
/// 方块高度
/// 方块竖数量
/// 输出文字
///
public static string GetValueAndDrawGrid_Other(Bitmap img, VectorOfVectorOfPoint contours,
int x_begin, int x_interval, int x_num, int y_begin, int y_interval, int y_num, string strText)
{
//画网格
//Mat mat_grid = DrawGridByXY(img, x_begin, x_interval, x_num, y_begin, y_interval, y_num);
int[] intArray = GetTargetValues_L_Other(contours, x_begin, x_interval, x_num, y_begin, y_interval, y_num, img, strText);
int maxValue = GetMaxValueOfArray(intArray);//数组最大值
string str = "";
//str += Environment.NewLine;//回车
str += strText;
if (maxValue >= 4 && maxValue < 10)
{
str += GetStringOfIntArray(intArray, "ABCDEFGH");
}
else
{
if (maxValue >= 10)
{
str += GetStringOfIntArray(intArray, "ABCDEFGH");
}
else
{
str += GetStringOfIntArray(intArray, "ABCDEFGH");
}
}
return str;
}
///
/// 拼接给定int数组内容,并返回拼接后字符串
///
///
///
public static string GetStringOfIntArray(int[] arr, string ss = "ABCD")
{
string str = "";
//char[] ch = new char[] { 'A', 'B', 'C', 'D', 'E', 'F', 'G' };
char[] ch = ss.ToCharArray();
foreach (int a in arr)
{
///
if (a >= 10)
{
string x = a.ToString();
char[] cc = x.ToArray();
int[] result = new int[cc.Length];
for (int i = 0; i < cc.Length; i++)
{
result[i] = Convert.ToInt32(x.Substring(i, 1));
}
Array.Sort(result);
int[] finalResult = result;
for (int j = 0; j < finalResult.Length; j++)
{
if (finalResult[j] == -1)
{
str += "null";
}
else
{
str += ch[finalResult[j]];
}
}
str += " ";
}
else
{
if (a == -1)
{
str += "null ";//未识别时,标示为空
}
else
{
str += ch[a] + " ";
}
}
}
return str;
}
///
/// 获取一维int数组中最大值
///
///
///
public static int GetMaxValueOfArray(int[] arr)
{
int[] dst = new int[arr.Length];
Array.Copy(arr, dst, arr.Length);//深度复制数组,防止排序对原数组产生影响
Array.Sort(dst);//数组排序
int maxValue = dst[arr.Length - 1];//数组最大值
return maxValue;
}
//
/// 根据给定的轮廓及范围信息计算涂卡的结果,返回int数组
///
///
///
///
///
///
///
///
///
public static int[] GetTargetValues_L_Other(VectorOfVectorOfPoint contours, int x_begin, int x_interval, int x_num,
int y_begin, int y_interval, int y_num, Bitmap img, string strText)
{
int[] result = new int[y_num];//结果数组
//数组初值默认为-1
for (int i = 0; i < y_num; i++)
{
result[i] = -1;
}
int x_max = x_begin + x_interval * x_num;
int y_max = y_begin + y_interval * y_num;
VectorOfVectorOfPoint targetContours = new VectorOfVectorOfPoint();
Point[] gravity = GetGravityOfContours(contours);//轮廓中心点坐标
for (int i = 0; i < contours.Size; i++)
{
VectorOfPoint contour = contours[i];
if (gravity[i].X < x_begin || gravity[i].X > x_max || gravity[i].Y < y_begin || gravity[i].Y > y_max)
{
continue;//判断中心点是否超出范围
}
int x_id = (int)Math.Floor((double)(gravity[i].Y - y_begin) / y_interval);//向右取整数
int value = (int)Math.Floor((double)(gravity[i].X - x_begin) / x_interval);
if (result[x_id] != -1)
{
}
else
{
result[x_id] = value;
}
}
return result;
}
///
/// 计算轮廓中心点坐标
///
/// 要计算中心点的轮廓
///
public static Point[] GetGravityOfContours(VectorOfVectorOfPoint selected_contours)
{
int ksize = selected_contours.Size;
double[] m00 = new double[ksize];
double[] m01 = new double[ksize];
double[] m10 = new double[ksize];
Point[] gravity = new Point[ksize];//用于存储轮廓中心点坐标
MCvMoments[] moments = new MCvMoments[ksize];
for (int i = 0; i < ksize; i++)
{
VectorOfPoint contour = selected_contours[i];
//计算当前轮廓的矩
moments[i] = CvInvoke.Moments(contour, false);
m00[i] = moments[i].M00;
m01[i] = moments[i].M01;
m10[i] = moments[i].M10;
int x = Convert.ToInt32(m10[i] / m00[i]);//计算当前轮廓中心点坐标
int y = Convert.ToInt32(m01[i] / m00[i]);
gravity[i] = new Point(x, y);
}
return gravity;
}
///
/// 获取裁剪 L T W H
///
///
public static Image GetMatCutImg(Bitmap bmp, int sX, int sT, int sW, int sH)
{
List> postionimageCut = new List>();
int L = sX;
int T = sT;
int W = sW;
int H = sH;
Rectangle rectangle = new Rectangle(L, T, W, H);
Image Sub = new Image(bmp).GetSubRect(rectangle);
Image CropImage = new Image(Sub.Size);
CvInvoke.cvCopy(Sub, CropImage, IntPtr.Zero);
return CropImage;
}
///
/// 检查边距是否合格
///
///
private string TempV(string[] GetData, string PYPostionList, int oldWidth, int oldHeight, string HideAreaPostionList)
{
double pyLeft = Convert.ToInt32(PYPostionList.Split(',')[0]);
double pyTop = Convert.ToInt32(PYPostionList.Split(',')[1]);
double Xtop = 0;
double Xleft = 0;
double Xwidth = 0;
double Xheight = 0;
if (GetData[1] != "")
{
string[] list = GetData[1].Split(',');
Xleft = Convert.ToDouble(list[0]);
Xtop = Convert.ToDouble(list[1]);
Xwidth = Convert.ToDouble(list[2]);
Xheight = Convert.ToDouble(list[3]);
if (Xleft < pyLeft)
{
return "学号编辑框左边超过定位点边界!";
}
if (Xleft + Xwidth - pyLeft > oldWidth)
{
return "学号编辑框右边超过定位点边界!";
}
if (Xtop < pyTop)
{
return "学号编辑框上边超过定位点边界!";
}
if (Xtop + Xheight - pyTop > oldHeight)
{
return "学号编辑框下边超过定位点边界!";
}
}
if (GetData[2] != "")//客观题
{
string[] keguantiList = GetData[2].Split('^');
foreach (string slist in keguantiList)
{
string[] list = slist.Split(',');
Xleft = Convert.ToDouble(list[0]);
Xtop = Convert.ToDouble(list[1]);
Xwidth = Convert.ToDouble(list[2]);
Xheight = Convert.ToDouble(list[3]);
string tihao = list[4] + "-" + list[5];
if (Xleft < pyLeft)
{
return "客观题:[" + tihao + "] 编辑框左边超过定位点边界!";
}
if (Xleft + Xwidth - pyLeft > oldWidth)
{
return "客观题:[" + tihao + "]编辑框右边超过定位点边界!";
}
if (Xtop < pyTop)
{
return "客观题:[" + tihao + "] 编辑框上边超过定位点边界!";
}
if (Xtop + Xheight - pyTop > oldHeight)
{
return "客观题:[" + tihao + "] 编辑框下边超过定位点边界!";
}
}
}
if (GetData[3] != "")//主观题
{
string[] keguantiList = GetData[3].Split('^');
foreach (string slist in keguantiList)
{
string[] list = slist.Split(',');
Xleft = Convert.ToDouble(list[0]);
Xtop = Convert.ToDouble(list[1]);
Xwidth = Convert.ToDouble(list[2]);
Xheight = Convert.ToDouble(list[3]);
string tihao = list[4];
if (Xleft < pyLeft)
{
return "主观题:[" + tihao + "] 编辑框左边超过定位点边界!";
}
if (Xleft + Xwidth - pyLeft > oldWidth)
{
return "主观题:[" + tihao + "] 编辑框右边超过定位点边界!";
}
if (Xtop < pyTop)
{
return "主观题:[" + tihao + "] 编辑框上边超过定位点边界!";
}
if (Xtop + Xheight - pyTop > oldHeight)
{
return "主观题:[" + tihao + "] 编辑框下边超过定位点边界!";
}
}
}
if (GetData[4] != "")//主观题
{
string[] keguantiList = GetData[4].Split('^');
foreach (string slist in keguantiList)
{
string[] list = slist.Split(',');
Xleft = Convert.ToDouble(list[0]);
Xtop = Convert.ToDouble(list[1]);
Xwidth = Convert.ToDouble(list[2]);
Xheight = Convert.ToDouble(list[3]);
string tihao = list[4];
if (Xleft < pyLeft)
{
return "题号:[" + tihao + "] 编辑框左边超过定位点边界!";
}
if (Xleft + Xwidth - pyLeft > oldWidth)
{
return "题号:[" + tihao + "] 编辑框右边超过定位点边界!";
}
if (Xtop < pyTop)
{
return "题号:[" + tihao + "] 编辑框上边超过定位点边界!";
}
if (Xtop + Xheight - pyTop > oldHeight)
{
return "题号:[" + tihao + "] 编辑框下边超过定位点边界!";
}
}
}
if (GetData[5] != "")
{
string[] list = GetData[5].Split(',');
Xleft = Convert.ToDouble(list[0]);
Xtop = Convert.ToDouble(list[1]);
Xwidth = Convert.ToDouble(list[2]);
Xheight = Convert.ToDouble(list[3]);
if (Xleft < pyLeft)
{
return "条码编辑框左边超过定位点边界!";
}
if (Xleft + Xwidth - pyLeft > oldWidth)
{
return "条码编辑框右边超过定位点边界!";
}
if (Xtop < pyTop)
{
return "条码编辑框上边超过定位点边界!";
}
if (Xtop + Xheight - pyTop > oldHeight)
{
return "条码编辑框下边超过定位点边界!";
}
}
if (GetData[7] != "")
{
string[] list = GetData[7].Split(',');
Xleft = Convert.ToDouble(list[0]);
Xtop = Convert.ToDouble(list[1]);
Xwidth = Convert.ToDouble(list[2]);
Xheight = Convert.ToDouble(list[3]);
if (Xleft < pyLeft)
{
return "条码编辑框左边超过定位点边界!";
}
if (Xleft + Xwidth - pyLeft > oldWidth)
{
return "条码编辑框右边超过定位点边界!";
}
if (Xtop < pyTop)
{
return "条码编辑框上边超过定位点边界!";
}
if (Xtop + Xheight - pyTop > oldHeight)
{
return "条码编辑框下边超过定位点边界!";
}
}
if (GetData[8] != "")
{
string[] list = GetData[8].Split(',');
Xleft = Convert.ToDouble(list[0]);
Xtop = Convert.ToDouble(list[1]);
Xwidth = Convert.ToDouble(list[2]);
Xheight = Convert.ToDouble(list[3]);
if (Xleft < pyLeft)
{
return "批阅分数编辑框左边超过定位点边界!";
}
if (Xleft + Xwidth - pyLeft > oldWidth)
{
return "批阅分数编辑框编辑框右边超过定位点边界!";
}
if (Xtop < pyTop)
{
return "批阅分数编辑框编辑框上边超过定位点边界!";
}
if (Xtop + Xheight - pyTop > oldHeight)
{
return "批阅分数编辑框编辑框下边超过定位点边界!";
}
}
if (HideAreaPostionList != "")
{
JavaScriptSerializer javaScriptSerializer = new JavaScriptSerializer();
List ht = javaScriptSerializer.Deserialize>(HideAreaPostionList);
int count = 0;
foreach (HideAreaData h in ht)
{
count++;
Xleft = Convert.ToDouble(h.left);
Xtop = Convert.ToDouble(h.top);
Xwidth = Convert.ToDouble(h.width);
Xheight = Convert.ToDouble(h.height);
if (Xleft < pyLeft)
{
return "屏蔽区" + count + "编辑框左边超过定位点边界!";
}
if (Xleft + Xwidth - pyLeft > oldWidth)
{
return "屏蔽区" + count + "编辑框右边超过定位点边界!";
}
if (Xtop < pyTop)
{
return "屏蔽区" + count + "编辑框上边超过定位点边界!";
}
if (Xtop + Xheight - pyTop > oldHeight)
{
return "屏蔽区" + count + "编辑框下边超过定位点边界!";
}
}
}
return "ok";
}
private Bitmap ScaleToSize(Bitmap bitmap, int width, int height)
{
if (bitmap == null)
{
return null;
}
if (bitmap.Width == width && bitmap.Height == height)
{
return bitmap;
}
var scaledBitmap = new Bitmap(width, height);
using (var g = Graphics.FromImage(scaledBitmap))
{
g.InterpolationMode = InterpolationMode.HighQualityBicubic;
g.DrawImage(bitmap, 0, 0, width, height);
}
return scaledBitmap;
}
//
/// 图片另存为
///
/// 路径
public Bitmap ImgGet(string url)
{
WebRequest imgRequest = WebRequest.Create(url);
HttpWebResponse res;
try
{
res = (HttpWebResponse)imgRequest.GetResponse();
}
catch (WebException ex)
{
res = (HttpWebResponse)ex.Response;
}
if (res.StatusCode.ToString() == "OK")
{
return new Bitmap((System.Drawing.Image)new Bitmap(imgRequest.GetResponse().GetResponseStream()));
}
else
{
return null;
}
}
public class HideAreaData
{
public Double width { get; set; }
public Double height { get; set; }
public Double left { get; set; }
public Double top { get; set; }
}
}