/// <summary> /// 导入样本 /// </summary> /// <param name="up"></param> /// <param name="department"></param> /// <param name="dataDicList"></param> /// <returns></returns> public static string Import_Sample(Fp_Common.UnameAndPwd up, string department, List <Dictionary <string, string> > dataDicList) { string username = Fp_Common.CookieHelper.GetCookieValue("username"); string result = string.Empty; bool check; Box_Path box_path = CreatTemFreezerPath(up, department, out check); if (check)//正常操作时需要判断是否存在当前结果以判断是否需要创建结构 { //需要创建盒子 result = ImportSamplesToFp(up, box_path, dataDicList); } else { result = ImportSamplesToFp(up, box_path, dataDicList); } if (result.Contains(@"\u8d85\u51fa\u6837\u54c1\u76d2.")) { int k; if (int.TryParse(box_path.Box, out k)) { box_path.Box = (k + 1).ToString(); } result = ImportSamplesToFp(up, box_path, dataDicList); } return(result); }
//提交数据新方法,一个dg一次提交 /// <summary> /// 提交样本数据到系统 /// </summary> /// <param name="up"></param> /// <param name="box_path"></param> /// <param name="dataDicList"></param> /// <returns></returns> public static string ImportSamplesToFp(Fp_Common.UnameAndPwd up, Box_Path box_path, List <Dictionary <string, string> > dataDicList) { string jsonsampledata = string.Empty; List <Dictionary <string, string> > jsonDicList = new List <Dictionary <string, string> >(); string box_type = "bag"; //默认放入袋子中 string create_storage = string.Empty; create_storage = string.Format("{0},{1},{2},{3}", box_path.Freezer, box_path.Level1, box_path.Level2, box_path.Level3); foreach (var dataDic in dataDicList) { if (!dataDic.ContainsKey("Freezer")) { dataDic.Add("Freezer", box_path.Freezer);//Tem } if (!dataDic.ContainsKey("Level1")) { dataDic.Add("Level1", box_path.Level1);//Username } if (!dataDic.ContainsKey("Level2")) { dataDic.Add("Level2", box_path.Level2);//月 } if (!dataDic.ContainsKey("Level3")) { dataDic.Add("Level3", box_path.Level3);//日 } if (!dataDic.ContainsKey("Box")) { dataDic.Add("Box", box_path.Box);//盒子 } } jsonsampledata = FpUtility.Fp_Common.FpJsonHelper.ObjectToJsonStr(dataDicList); Dictionary <string, string> jsonDic = new Dictionary <string, string>(); jsonDic.Add("create_storage", create_storage); jsonDic.Add("box_type", box_type); jsonDic.Add("json", jsonsampledata); string importRes = ImportSampleToFp(up, jsonDic); return(importRes); }
//第一步到指定位置查找空位 //第二部找到位置就添加样本 //第三部没好到就添加样本盒(样本盒名称怎么获取)--获取冰箱(根据名称)--->根据冰箱名获取冰箱id-->根据冰箱id获取冰箱分支---->根据用户名获取对应的分支id---->月份分支---->日分支id----->boxes获取当前分支下的所有盒子,判断盒子是否存在(根据名字判断盒子) //生成默认临时储存结构的方法--目的,查看对应位置是否存在可以存放样本的孔 /// <summary> /// 根据日期创建一个临时的冰箱 /// </summary> /// <param name="up"></param> /// <param name="department"></param> /// <param name="creat"></param> /// <returns></returns> private static Fp_Model.Box_Path CreatTemFreezerPath(Fp_Common.UnameAndPwd up, string department, out bool creat) { FpUtility.Fp_Model.Box_Path box_path = new Box_Path(); ////Tem-->username-->month-->day(-->box) //string box_path = string.Empty; string username = Fp_Common.CookieHelper.GetCookieValue("username"); string freezerName = "Tem--" + department; if (!string.IsNullOrEmpty(username)) { Fp_Model.Freezer freezer = Freezers.GetBy(up, freezerName); string _path = string.Format("{0}→{1}→{2}月→{3}日", freezerName, username, DateTime.Now.Month, DateTime.Now.Date.ToString("dd"));//创建盒子路径 //获取次路径下的盒子 if (freezer != null) { Fp_Model.Subdivision subdivision = Subdivisions.CheckBy(up, freezer.id, _path); //要判断是否为空 if (subdivision != null) { if (subdivision.name.Contains("日")) { List <Fp_Model.Box> boxsList = Fp_BLL.Boxes.GetAll(up, subdivision.id); if (boxsList.Count > 0) { //日期节点下有盒子 Fp_Model.Box maxBox = boxsList.OrderByDescending(a => a.name).FirstOrDefault(); string maxBoxName = maxBox.name.Replace(maxBox.location + "→", "").Trim(); if (!string.IsNullOrEmpty(maxBoxName)) { box_path.Freezer = "Tem--" + department; box_path.Level1 = username; box_path.Level2 = DateTime.Now.Month + "月"; box_path.Level3 = DateTime.Now.Date.ToString("dd") + "日"; box_path.Box = maxBoxName; creat = false; //此处还需要判断当前的bag中是否有位置存放样品 } else { int max = 0; //意外报错 if (int.TryParse(maxBoxName, out max)) { box_path.Freezer = "Tem--" + department; box_path.Level1 = username; box_path.Level2 = DateTime.Now.Month + "月"; box_path.Level3 = DateTime.Now.Date.ToString("dd") + "日"; box_path.Box = (max + 1).ToString(); } creat = true; } } else { creat = true; //日期节点下没盒子 box_path.Freezer = "Tem--" + department; box_path.Level1 = username; box_path.Level2 = DateTime.Now.Month + "月"; box_path.Level3 = DateTime.Now.Date.ToString("dd") + "日"; box_path.Box = "1"; } } else { //不包含日 creat = true; //当前节点下没盒子 box_path.Freezer = "Tem--" + department; box_path.Level1 = username; box_path.Level2 = DateTime.Now.Month + "月"; box_path.Level3 = DateTime.Now.Date.ToString("dd") + "日"; box_path.Box = "1"; } } else { creat = true; //当前节点下没盒子 box_path.Freezer = "Tem--" + department; box_path.Level1 = username; box_path.Level2 = DateTime.Now.Month + "月"; box_path.Level3 = DateTime.Now.Date.ToString("dd") + "日"; box_path.Box = "1"; } } else { creat = true; box_path.Freezer = "Tem--" + department; box_path.Level1 = username; box_path.Level2 = DateTime.Now.Month + "月"; box_path.Level3 = DateTime.Now.Date.ToString("dd") + "日"; box_path.Box = "1";; } } else { creat = true; } return(box_path); }
/// <summary> ///创建盒子保存样本 /// </summary> /// <param name="up"></param> /// <param name="sample_type"></param> /// <param name="count"></param> /// <param name="box_path"></param> /// <param name="dataDic"></param> /// <returns></returns> private static string ImportSamplesToFp(Fp_Common.UnameAndPwd up, string sample_type, string count, Box_Path box_path, Dictionary <string, string> dataDic) { string jsonsampledata = string.Empty; List <Dictionary <string, string> > jsonDicList = new List <Dictionary <string, string> >(); string box_type = "bag"; //默认放入袋子中 string create_storage = string.Empty; int kk = 1; Random rand = new Random(); int ALIQUOT = rand.Next(1, 1000); #region 创建样本信息字符串&json= if (int.TryParse(count, out kk)) { if (!dataDic.ContainsKey("ALIQUOT")) { dataDic.Add("ALIQUOT", ALIQUOT.ToString()); } if (!dataDic.ContainsKey("Sample Type")) { dataDic.Add("Sample Type", sample_type); } if (!dataDic.ContainsKey("Freezer")) { dataDic.Add("Freezer", box_path.Freezer);//Tem } if (!dataDic.ContainsKey("Level1")) { dataDic.Add("Level1", box_path.Level1);//Username } if (!dataDic.ContainsKey("Level2")) { dataDic.Add("Level2", box_path.Level2);//月 } if (!dataDic.ContainsKey("Level3")) { dataDic.Add("Level3", box_path.Level3);//日 } create_storage = string.Format("{0},{1},{2},{3}", box_path.Freezer, box_path.Level1, box_path.Level2, box_path.Level3); if (dataDic.ContainsKey("Box")) { dataDic["Box"] = box_path.Box; } else { dataDic.Add("Box", box_path.Box);//袋子中不需要指定位置 } if (string.IsNullOrEmpty(jsonsampledata)) { if (kk == 1) { //单条数据 jsonsampledata = FpJsonHelper.DictionaryToJsonString(dataDic); } else if (kk > 1 && kk < 500) { for (int i = 0; i < kk; i++) { //扩展数据成多条 Dictionary <string, string> tem = new Dictionary <string, string>(); //字典复制需要两次循环,这里是利用字典的序列化和反序列化 tem = Fp_Common.FpJsonHelper.DeserializeObject <Dictionary <string, string> >(Fp_Common.FpJsonHelper.DictionaryToJsonString(dataDic)); jsonDicList.Add(tem); } //多条数据 jsonsampledata = FpJsonHelper.DictionaryListToJsonString(jsonDicList); } } } #endregion Dictionary <string, string> jsonDic = new Dictionary <string, string>(); jsonDic.Add("create_storage", create_storage); jsonDic.Add("box_type", box_type); jsonDic.Add("json", jsonsampledata); string importRes = ImportSampleToFp(up, jsonDic); return(importRes); }