예제 #1
0
        internal void jsonDataDelete(List <Dictionary <string, int> > deletes)
        {
            //存入json
            String dataJson = Util.read2File("data/" + sampleModel.sampleNo + ".json", FileMode.Open, FileAccess.Read);

            if (JsonSplit.IsJson(dataJson))
            {
                sampleModel = Util.JsonToObj <SampleModel>(dataJson);
                List <String> dataTemp = new List <string>();
                for (int i = 0; i < sampleModel.data.Count; i++)
                {
                    var Query = from delete in deletes
                                where delete["OrderNum"] == i
                                select delete;

                    if (Query.Count <Dictionary <String, int> >() <= 0)
                    {
                        dataTemp.Add(sampleModel.data[i]);
                    }
                }
                sampleModel.data.Clear();
                sampleModel.data.AddRange(dataTemp);

                Util.write2File("data/" + sampleModel.sampleNo + ".json", Util.ObjToJson <SampleModel>(sampleModel), System.IO.FileMode.Create, System.IO.FileAccess.Write);
            }
        }
예제 #2
0
        /// <summary>
        /// 从cookie获取用户信息
        /// </summary>
        /// <returns></returns>
        public Account GetAccountByCookie()
        {
            var cookie = CookieHelper.GetCookie("cookie_rememberme");

            if (cookie != null)
            {
                if (!string.IsNullOrEmpty(cookie.Value))
                {
                    //解密
                    var cookirvalue = new Common.CryptHelper.AESCrypt().Decrypt(cookie.Value);
                    if (!JsonSplit.IsJson(cookirvalue))
                    {
                        return(null);
                    }
                    try
                    {
                        var jsonFormat = Common.JsonConverter.ConvertJson(cookirvalue);
                        if (jsonFormat != null)
                        {
                            var user = UserLogin(jsonFormat.username, new Common.CryptHelper.AESCrypt().Decrypt(jsonFormat.password));
                            if (user != null)
                            {
                                return(GetAccountByUser(user));
                            }
                        }
                    }
                    catch (Exception)
                    {
                        return(null);
                    }
                }
            }
            return(null);
        }
예제 #3
0
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");
            String str = "{name:123}";

            Console.WriteLine(JsonSplit.IsJsonStart(ref str));
        }
예제 #4
0
 /// <summary>
 /// 将Json 数组分隔成多个键值对。
 /// </summary>
 public static List <Dictionary <string, string> > SplitArray(string jsonArray)
 {
     if (string.IsNullOrEmpty(jsonArray))
     {
         return(null);
     }
     jsonArray = jsonArray.Trim();
     return(JsonSplit.Split(jsonArray));
 }
예제 #5
0
        /// <summary>
        /// 将Json分隔成键值对。
        /// </summary>
        public static Dictionary <string, string> Split(string json)
        {
            var result = JsonSplit.Split(json);

            if (result != null && result.Count > 0)
            {
                return(result[0]);
            }
            return(null);
        }
예제 #6
0
 /// <summary>
 /// 判断JSON字符串是否合法
 /// </summary>
 /// <param name="jsonStr">传入的json串</param>
 /// <returns></returns>
 public string Check(string jsonStr)
 {
     if (JsonSplit.IsJson(jsonStr))
     {
         return(JSONHelper.ObjectToJSON(jsonStr));
     }
     else
     {
         return(JSONHelper.ConvertJsonString(jsonStr));
     }
 }
예제 #7
0
        private static string GetXml(Dictionary <string, string> dic, bool isWithAttr)
        {
            var sb     = Pool.StringBuilder.Get();
            var isJson = false;

            foreach (var item in dic)
            {
                isJson = IsJson(item.Value);
                if (!isJson)
                {
                    sb.AppendFormat("<{0}>{1}</{0}>", item.Key, FormatCdata(item.Value));
                }
                else
                {
                    var jsonList = JsonSplit.Split(item.Value);
                    if (jsonList != null && jsonList.Count > 0)
                    {
                        if (!isWithAttr)
                        {
                            sb.AppendFormat("<{0}>", item.Key);
                        }
                        for (var j = 0; j < jsonList.Count; j++)
                        {
                            if (isWithAttr)
                            {
                                sb.Append(GetXmlElement(item.Key, jsonList[j]));
                            }
                            else
                            {
                                sb.Append(GetXml(jsonList[j], isWithAttr));
                            }
                        }
                        if (!isWithAttr)
                        {
                            sb.AppendFormat("</{0}>", item.Key);
                        }
                    }
                    else // 空Json {}
                    {
                        sb.AppendFormat("<{0}></{0}>", item.Key);
                    }
                }
            }
            return(sb.Put());
        }
예제 #8
0
        /**
         * 更新json数据文件
         * */
        private void updateDataJsonFile(String sampleNo, String key, String value)
        {
            if (sampleModel.sampleNo != "")
            {
                String dataJson = Util.read2File("data/" + sampleModel.sampleNo + ".json", FileMode.Open, FileAccess.Read);
                if (JsonSplit.IsJson(dataJson))
                {
                    sampleModel = Util.JsonToObj <SampleModel>(dataJson);
                    switch (key)
                    {
                    case "sampleType":
                        sampleModel.sampleType = value;
                        break;

                    case "device":
                        sampleModel.device = value;
                        break;

                    case "sampleProject":
                        sampleModel.sampleProject = value;
                        break;

                    case "sampleName":
                        sampleModel.sampleName = value;
                        break;

                    case "productName":
                        sampleModel.productName = value;
                        break;

                    case "methodName":
                        sampleModel.methodName = value;
                        break;

                    case "temperature":
                        sampleModel.temperature = value;
                        break;
                    }

                    Util.write2File("data/" + sampleModel.sampleNo + ".json", Util.ObjToJson <SampleModel>(sampleModel), System.IO.FileMode.Create, System.IO.FileAccess.Write);
                }
            }
        }
예제 #9
0
        //加载工程文件
        private void loadFromJson(String path)
        {
            String dataJson = Util.read2File(path, FileMode.Open, FileAccess.Read);

            if (JsonSplit.IsJson(dataJson))
            {
                sampleModel = Util.JsonToObj <SampleModel>(dataJson);
                setInputValue(sampleModel);
                button1.Enabled = false;
                button2.Enabled = false;
                button3.Enabled = true;
                enabledInput();
                countTextBox.Text = sampleModel.data.Count.ToString();
                if (comDataManager != null)
                {
                    comDataManager.resetData(Int32.Parse(sampleModel.samplePointNum), sampleModel.data);
                }
                sampleModel.data.Clear();
                System.GC.Collect();
            }
        }
예제 #10
0
        internal async Task EnterInsertAsync(HttpContext context, Exception exception = null)
        {
            string result = string.Empty;

            if (context.Request.Path.HasValue)
            {
                if (context.Request.Path.Value.IndexOf("/V2/ErrLogRecord", StringComparison.OrdinalIgnoreCase) >= 0 ||
                    context.Request.Path.Value.IndexOf("/V2/LogRecord", StringComparison.OrdinalIgnoreCase) >= 0 ||
                    context.Request.Path.Value.IndexOf("/V2/LogTrace", StringComparison.OrdinalIgnoreCase) >= 0 ||
                    context.Request.Path.Value.IndexOf("/V2/ExtraLog", StringComparison.OrdinalIgnoreCase) >= 0)
                {
                    if (JsonSplit.IsJson(context.Items[SettingHelper.Re_quest].ToString()))
                    {
                        ClientLog(context.Items[SettingHelper.Re_quest].ToString(), context.Items[SettingHelper.App_lication].ToString());
                    }
                    else
                    {
                        if (exception != null)
                        {
                            await NormalAsync(context, exception);
                        }
                        else
                        {
                            await NormalAsync(context);
                        }
                    }
                }
                else
                {
                    if (exception != null)
                    {
                        await NormalAsync(context, exception);
                    }
                    else
                    {
                        await NormalAsync(context);
                    }
                }
            }
        }
예제 #11
0
        /// <summary>
        /// 将一个Json转成Xml
        /// </summary>
        /// <param name="json">Json字符串</param>
        /// <param name="isWithAttr">是否转成属性,默认true</param>
        /// <returns></returns>
        public static string ToXml(string json, bool isWithAttr)
        {
            var sb = Pool.StringBuilder.Get();

            sb.Append("<?xml version=\"1.0\"  standalone=\"yes\"?>");
            var dicList = JsonSplit.Split(json);

            if (dicList != null && dicList.Count > 0)
            {
                var addRoot = dicList.Count > 1 || dicList[0].Count > 1;
                if (addRoot)
                {
                    sb.Append("<root>");//</root>";
                }

                sb.Append(GetXmlList(dicList, isWithAttr));

                if (addRoot)
                {
                    sb.Append("</root>");//</root>";
                }
            }
            return(sb.Put());
        }
예제 #12
0
 //硬度参数变化时
 private void sampleHardnessCombox_SelectedIndexChanged(object sender, EventArgs e)
 {
     try
     {
         //存入ini
         ini.IniWriteValue("样本数据", "sampleHardness", ((ComboBox)sender).SelectedItem.ToString());
         if (sampleModel.sampleNo != "")
         {
             //存入json
             String dataJson = Util.read2File("data/" + sampleModel.sampleNo + ".json", FileMode.Open, FileAccess.Read);
             if (JsonSplit.IsJson(dataJson))
             {
                 sampleModel = Util.JsonToObj <SampleModel>(dataJson);
                 sampleModel.sampleHardness = ((ComboBox)sender).SelectedItem.ToString();
                 sampleModel.sampleProject  = ((ComboBox)sender).SelectedItem.ToString();
                 //获取数据
                 List <String> matchData = Util.getMatchData(Util.read2File("data/" + sampleModel.sampleNo + ".txt", FileMode.Open, FileAccess.Read), sampleModel.sampleHardness + @":\s+(\d+\.\d)");
                 sampleModel.data = matchData;
                 setCountText(sampleModel.data.Count.ToString());
                 //如果当前datagridview中有数据,则重新排列gridview
                 if (comDataManager != null)
                 {
                     comDataManager.resetData(Int32.Parse(sampleModel.samplePointNum), sampleModel.data);
                 }
                 Util.write2File("data/" + sampleModel.sampleNo + ".json", Util.ObjToJson <SampleModel>(sampleModel), System.IO.FileMode.Create, System.IO.FileAccess.Write);
                 sampleModel.data.Clear();
                 System.GC.Collect();
             }
         }
     }
     catch (Exception err)
     {
         log.Error(err.ToString());
         MessageBox.Show("项目切换失败", "提示");
     }
 }
예제 #13
0
        private void samplePointNum_SelectedIndexChanged(object sender, EventArgs e)
        {
            //存入ini
            ini.IniWriteValue("样本数据", "samplePointNum", ((ComboBox)sender).SelectedIndex.ToString());

            //存入json
            if (sampleModel.sampleNo != "")
            {
                String dataJson = Util.read2File("data/" + sampleModel.sampleNo + ".json", FileMode.Open, FileAccess.Read);
                if (JsonSplit.IsJson(dataJson))
                {
                    sampleModel = Util.JsonToObj <SampleModel>(dataJson);
                    sampleModel.samplePointNum = ((ComboBox)sender).SelectedItem.ToString();
                    //如果当前datagridview中有数据,则重新排列gridview
                    if (comDataManager != null)
                    {
                        comDataManager.resetData(Int32.Parse(sampleModel.samplePointNum), sampleModel.data);
                    }
                    Util.write2File("data/" + sampleModel.sampleNo + ".json", Util.ObjToJson <SampleModel>(sampleModel), System.IO.FileMode.Create, System.IO.FileAccess.Write);
                    sampleModel.data.Clear();
                    System.GC.Collect();
                }
            }
        }
예제 #14
0
 //单元格编辑事件
 private void CellEndEdit(object sender, DataGridViewCellEventArgs e)
 {
     if (e.RowIndex * columnNo + e.ColumnIndex < lastrow * columnNo + lastcolumn)
     {
         dt.Rows[e.RowIndex][e.ColumnIndex] = dataGridView.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString();
         String dataJson = Util.read2File("data/" + mainForm.sampleModel.sampleNo + ".json", FileMode.Open, FileAccess.Read);
         if (JsonSplit.IsJson(dataJson))
         {
             mainForm.sampleModel = Util.JsonToObj <SampleModel>(dataJson);
             int index = Int32.Parse(mainForm.sampleModel.samplePointNum) * e.RowIndex + e.ColumnIndex;
             if (index < mainForm.sampleModel.data.Count)
             {
                 mainForm.sampleModel.data[index] = ((DataGridView)sender).Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString();
                 Util.write2File("data/" + mainForm.sampleModel.sampleNo + ".json", Util.ObjToJson <SampleModel>(mainForm.sampleModel), System.IO.FileMode.Create, System.IO.FileAccess.Write);
                 mainForm.sampleModel.data.Clear();
             }
         }
     }
     else
     {
         dataGridView.CancelEdit();
         MessageBox.Show("该单元格不可编辑", "警告");
     }
 }
예제 #15
0
        /// <summary>
        /// 从Cookie中获取用户信息
        /// </summary>
        public Account GetAccountByCookie()
        {
            var cookie = CookieHelper.GetCookie(LoginType.ToString());

            if (cookie != null)
            {
                //验证json的有效性
                if (!string.IsNullOrEmpty(cookie.Value))
                {
                    //解密
                    var cookievalue = Common.CryptHelper.DESCrypt.Decrypt(cookie.Value);
                    if (!string.IsNullOrEmpty(cookievalue))
                    {
                        //是否为json
                        if (!JsonSplit.IsJson(cookievalue))
                        {
                            return(null);
                        }
                        try
                        {
                            var jsonFormat = Common.JsonConverter.ConvertJson(cookievalue);
                            if (jsonFormat != null && jsonFormat.token == DB.ValidCookieString)
                            {
                                string id        = jsonFormat.id;
                                string username  = jsonFormat.username;
                                string loginname = jsonFormat.loginname;
                                string userpwd   = jsonFormat.password;
                                string pwd2      = DB.ValidCookieString;
                                string logintype = jsonFormat.logintype;
                                string roleId    = jsonFormat.roleid;
                                string isadmin   = "false";
                                if (logintype == Enums.LoginType.member.ToString())
                                {
                                    isadmin = jsonFormat.isadmin;
                                }
                                int roleid = 1;
                                int.TryParse(roleId, out roleid);
                                if (LoginType == Enums.LoginType.member)
                                {
                                    pwd2 = jsonFormat.pwd2;
                                }

                                Account account = new Account()
                                {
                                    Id        = id,
                                    Name      = username,
                                    LoginName = loginname,
                                    PassWord  = userpwd,
                                    PassWord2 = pwd2,
                                    LoginType = LoginType.ToString(),
                                    IsAdmin   = Convert.ToBoolean(isadmin),
                                    RoleID    = roleid
                                                //Role_Nav = DB.Sys_Role_Nav.Where(a => a.role_id == roleid).ToList()
                                };
                                return(account);
                            }
                        }
                        catch { return(null); }
                    }
                }
            }
            return(null);
        }
예제 #16
0
        //导出按钮点击

        private void button3_Click(object sender, EventArgs e)
        {
            //生成报告
            String separator = " ";

            switch (sampleModel.samplePointNum)
            {
            case "3":
                separator = ini.IniReadValue("记录设置", "separator3").Replace("&nbsp;", " ");
                break;

            case "4":
                separator = ini.IniReadValue("记录设置", "separator4").Replace("&nbsp;", " ");;
                break;

            case "5":
                separator = ini.IniReadValue("记录设置", "separator5").Replace("&nbsp;", " ");
                break;

            default:

                break;
            }

            //根据数据数量确定excel 文件数
            String dataJson = Util.read2File("data/" + sampleModel.sampleNo + ".json", FileMode.Open, FileAccess.Read);

            if (!JsonSplit.IsJson(dataJson))
            {
                MessageBox.Show("请新建记录!", "提示"); return;
            }
            sampleModel = Util.JsonToObj <SampleModel>(dataJson);
            int excelNum = (int)Math.Ceiling((decimal)sampleModel.data.Count / (decimal)(40 * Int32.Parse(sampleModel.samplePointNum)));

            //循环excel 填入数据
            String[][] insertData = Util.dataFormat(sampleModel.data, Int32.Parse(sampleModel.samplePointNum));

            List <String> averages = new List <string>();

            if (insertData == null)
            {
                MessageBox.Show("无数据!", "提示"); return;
            }
            Workbook  combineWorkbook = new Workbook();
            Worksheet sheet;
            int       mark = 0;

            for (int i = 0; i < excelNum; i++)
            {
                try
                {
                    //打开excel文件
                    using (FileStream fs = File.OpenRead("model/template.xls"))
                    {
                        Workbook workbook = new Workbook(fs);
                        if (workbook == null)
                        {
                            return;
                        }
                        sheet = workbook.Worksheets[0];
                        //填入表头数据

                        sheet.Cells.Rows[1][0].Value = ini.IniReadValue("记录设置", "recordCode");
                        sheet.Cells.Rows[1][9].Value = @"       " + (i + 1);      //编号
                        sheet.Cells.Rows[2][2].Value = sampleModel.sampleNo;      //委托编号
                        autoFontSize(sampleModel.sampleNo, sheet.Cells.Rows[2][2], 46, 1000);
                        sheet.Cells.Rows[2][5].Value = sampleModel.device;        //试验机号
                        autoFontSize(sampleModel.device, sheet.Cells.Rows[2][5], 46, 153);
                        sheet.Cells.Rows[2][9].Value = sampleModel.temperature;   //温度
                        sheet.Cells.Rows[3][2].Value = sampleModel.sampleName;    //样品名称
                        autoFontSize(sampleModel.sampleName, sheet.Cells.Rows[3][2], 46, 1000);
                        sheet.Cells.Rows[3][7].Value = sampleModel.sampleType;    //规格型号
                        autoFontSize(sampleModel.sampleType, sheet.Cells.Rows[3][7], 46, 1000);
                        sheet.Cells.Rows[4][2].Value = sampleModel.sampleProject; //检验项目
                        autoFontSize(sampleModel.sampleProject, sheet.Cells.Rows[4][2], 46, 1000);
                        sheet.Cells.Rows[4][5].Value = sampleModel.productName;   //产品标准
                        autoFontSize(sampleModel.productName, sheet.Cells.Rows[4][5], 46, 96);
                        sheet.Cells.Rows[4][8].Value = sampleModel.methodName;    //方法标准
                        autoFontSize(sampleModel.methodName, sheet.Cells.Rows[4][8], 46, 1000);
                        sheet.Cells.Rows[5][1].Value = "读数(" + sampleModel.sampleHardness + ")";
                        sheet.Cells.Rows[5][6].Value = "读数(" + sampleModel.sampleHardness + ")";
                        //填入试验数据
                        int row = 6;
                        int col = 1;
                        int max = insertData.Length > (i + 1) * 40 ? (i + 1) * 40 : insertData.Length;
                        for (int cur = mark; cur < max; cur++)
                        {
                            sheet.Cells.Rows[row][col].Value     = String.Join(separator, insertData[cur]);
                            sheet.Cells.Rows[row][col + 3].Value = (Util.sum(insertData[cur], 3) / 3).ToString("0.0");
                            averages.Add((Util.sum(insertData[cur], 3) / 3).ToString("0.0"));
                            if (row == 25)
                            {
                                row = 6;
                                col = 6;
                            }
                            else
                            {
                                row++;
                            }
                            mark++;
                        }
                        combineWorkbook.Combine(workbook);
                    }
                }
                catch (Exception err)
                {
                    log.Error(err.ToString());
                    MessageBox.Show("导出失败,详情请查看日志", "提示");
                    return;
                }
            }
            sampleModel.data.Clear();
            insertData = null;
            //pdf合并excel文件,删除excel文件

            //保存目标PDF文件

            if (combineWorkbook != null)
            {
                try
                {
                    String folderPath = ini.IniReadValue("输出设置", "folderPath") + @"\";
                    if (!Directory.Exists(folderPath))
                    {
                        folderPath = Application.StartupPath + @"\output\";
                    }
                    String exportType = ini.IniReadValue("输出设置", "exportType");
                    switch (exportType)
                    {
                    case "pdf":
                        combineWorkbook.Save(folderPath + sampleModel.sampleNo + ".pdf", Aspose.Cells.SaveFormat.Pdf);
                        break;

                    case "xlsx":
                        combineWorkbook.Save(folderPath + sampleModel.sampleNo + ".xlsx", Aspose.Cells.SaveFormat.Xlsx);
                        break;

                    case "csv":
                        combineWorkbook.Save(folderPath + sampleModel.sampleNo + ".csv", Aspose.Cells.SaveFormat.CSV);
                        break;

                    case "html":
                        combineWorkbook.Save(folderPath + sampleModel.sampleNo + ".html", Aspose.Cells.SaveFormat.Html);
                        break;

                    default:
                        combineWorkbook.Save(folderPath + sampleModel.sampleNo + ".pdf", Aspose.Cells.SaveFormat.Pdf);
                        break;
                    }
                    String averageText = String.Join(";", averages.ToArray());
                    averageTextBox.Text = averageText;
                    Util.write2File(folderPath + sampleModel.sampleNo + "-平均值.txt", averageText, FileMode.Create, FileAccess.Write);
                    MessageBox.Show("导出记录成功", "提示");
                    sampleModel = new SampleModel();
                    if (comDataManager != null)
                    {
                        comDataManager.clear();
                    }
                    countTextBox.Text = "0";
                    button1.Enabled   = true;
                    button2.Enabled   = true;
                    button3.Enabled   = false;
                    unEnabledInput();
                }
                catch (Exception err)
                {
                    log.Error(err.ToString());
                    MessageBox.Show("导出记录失败,详情请查看日志", "提示");
                }
            }
        }
예제 #17
0
 /// <summary>
 /// 检测是否Json格式的字符串
 /// </summary>
 /// <param name="json">要检测的字符串</param>
 /// <param name="errIndex">错误的字符索引</param>
 /// <returns></returns>
 public static bool IsJson(string json, out int errIndex)
 {
     return(JsonSplit.IsJson(json, out errIndex));
 }
예제 #18
0
        /// <summary>
        /// 校验数据是否正确
        /// </summary>
        /// <param name="fileLocalAllPath">文件本地全路径</param>
        /// <returns></returns>
        private bool checkDownFile(string fileLocalAllPath)
        {
            string extenName = Path.GetExtension(fileLocalAllPath);

            if (!File.Exists(fileLocalAllPath))
            {
                return(false);
            }

            StreamReader streamReader = new StreamReader(new FileStream(fileLocalAllPath, FileMode.Open, FileAccess.Read), Encoding.UTF8);
            string       lineText     = streamReader.ReadLine();

            streamReader.Close();
            // string checkText = lineText.Substring(0, 3);
            bool  isOk     = false;
            Regex regChina = new Regex("[^\x00-\xFF]+");//匹配中文或是乱码,这里不存在中文,所以为乱码

            switch (extenName)
            {
            case ".js":
            {
                bool isError = regChina.IsMatch(lineText);
                isOk = !isError;
                break;
            }

            case ".css":
            {
                bool isError = regChina.IsMatch(lineText);
                isOk = !isError;
                break;
            }

            case ".png":
            {
                isOk = lineText.Contains(FileHeadEnum.PNG.GetRemark());
                break;
            }

            case ".json":
            {
                string readAllText = File.ReadAllText(fileLocalAllPath);
                bool   isJson      = JsonSplit.IsJson(readAllText);
                isOk = isJson;
                break;
            }

            case ".dds":
            {
                isOk = lineText.Contains(FileHeadEnum.DDS.GetRemark());
                break;
            }

            default:
            {
                isOk = true;
                break;
            }
            }
            return(isOk);
        }
예제 #19
0
 /// <summary>
 /// 检测是否Json格式的字符串
 /// </summary>
 /// <param name="json">要检测的字符串</param>
 public static bool IsJson(string json)
 {
     return(JsonSplit.IsJson(json));
 }