示例#1
0
        public Dictionary <int, List <int> > upload_base_recorddetails(string newfile, string fileName, string action,
                                                                       JObject json_formdata, string recordinfoid)
        {
            Base_Company_Method          bcm = new Base_Company_Method();
            Switch_helper_Base_blend_web sw  = new Switch_helper_Base_blend_web();
            DataTable     dtExcel            = bcm.GetExcelData_Table(Server.MapPath(newfile), 0);
            List <string> stringList         = new List <string>();

            //记住发生错误的行数
            List <int> errorlines = new List <int>();

            //记住插入成功的个数
            int count = 0;

            Sql.busi_RecordInfor bc = new Sql.busi_RecordInfor();
            //插入成功的个数(返回放入dictionary)
            List <int> successinsert = new List <int>();
            //返回值
            Dictionary <int, List <int> > returndic = new Dictionary <int, List <int> >();

            try
            {
                for (int i = 0; i < dtExcel.Rows.Count; i++)
                {
                    for (int j = 0; j < dtExcel.Columns.Count; j++)
                    {
                        stringList.Add(dtExcel.Rows[i][j].ToString());
                    }

                    //项号
                    if (i == 8)
                    {
                    }
                    RecordDetailEn detail  = new RecordDetailEn(stringList, json_formdata);
                    string         jsonStr = JsonConvert.SerializeObject(detail);
                    JObject        json    = (JObject)JsonConvert.DeserializeObject(jsonStr);

                    if (bc.check_repeat_record_details(json, recordinfoid).Rows.Count > 0)
                    {
                        errorlines.Add(i + 2);
                    }
                    else
                    {
                        int f = bc.insert_record_details(recordinfoid, json);
                        if (f > 0)
                        {
                            count = count + 1;
                        }
                        else
                        {
                            errorlines.Add(i + 2);
                        }
                    }
                    stringList.Clear();
                }
                successinsert.Add(count);
                returndic.Add(1, successinsert);
                returndic.Add(2, errorlines);
            }
            catch (Exception ex)
            {
            }
            return(returndic);
        }
示例#2
0
        private void save_recorddetails()
        {
            string  recordinfoid = Request["recordinfoid"];
            string  formdata     = Request["formdata"];
            JObject json         = (JObject)JsonConvert.DeserializeObject(formdata);

            Sql.busi_RecordInfor br = new Sql.busi_RecordInfor();
            Base_Codename_Method bm = new Base_Codename_Method();
            string response         = String.Empty;

            if (string.IsNullOrEmpty(json.Value <string>("ID")))
            {
                if (json.Value <string>("ENABLED") == "1")
                {
                    if (br.check_repeat_record_details(json, recordinfoid).Rows.Count > 0)
                    {
                        //当数据有重复时success返回值为4
                        response = "{\"success\":\"4\"}";
                    }
                    else
                    {
                        int i = br.insert_record_details(recordinfoid, json);
                        response = "{\"success\":" + (i > 0 ? "true" : "false") + "}";
                    }
                }
                else
                {
                    int i = br.insert_record_details(recordinfoid, json);
                    response = "{\"success\":" + (i > 0 ? "true" : "false") + "}";
                }
            }
            else
            {
                if (json.Value <string>("ENABLED") == "1")
                {
                    if (br.check_update_repeat_record_details(json, recordinfoid).Rows.Count > 0)
                    {
                        //当数据有重复时success返回值为4
                        response = "{\"success\":\"4\"}";
                    }
                    else
                    {
                        //更新
                        DataTable dt = br.get_before_change_record_details(json);
                        int       i  = br.update_record_details(json, recordinfoid);
                        if (i > 0)
                        {
                            string content = bm.getrecordinfodetails(dt, json);
                            br.insert_alert_record_details(json, content);
                            response = "{\"success\":" + (i > 0 ? "true" : "false") + "}";
                        }
                    }
                }
                else
                {
                    //更新
                    DataTable dt = br.get_before_change_record_details(json);
                    int       i  = br.update_record_details(json, recordinfoid);
                    if (i > 0)
                    {
                        string content = bm.getrecordinfodetails(dt, json);
                        br.insert_alert_record_details(json, content);
                        response = "{\"success\":" + (i > 0 ? "true" : "false") + "}";
                    }
                }
            }
            Response.Write(response);
            Response.End();
        }