Пример #1
0
        public Dictionary <int, List <int> > upload_base_company(string newfile, string fileName, string action,
                                                                 JObject json_formdata)
        {
            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> >();

            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());
                }
                //备案号                           //账册属性
                string code = stringList[0]; string BOOKATTRIBUTE = stringList[1];
                //规格型号启用
                string ISMODEL = stringList[6] == "是" ? "1" : "0";
                //是否启用
                string ENABLED = stringList[7] == "是" ? "1" : "0";
                //BUSIUNIT
                string BUSIUNIT = stringList[2];
                //RECEIVEUNIT
                string RECEIVEUNIT = stringList[3];
                //TRADE
                string TRADE = stringList[4];
                //EXEMPTING
                string EXEMPTING = stringList[5];
                //remark
                string REMARK = stringList[8];

                //启用日期
                string startdate = json_formdata.Value <string>("STARTDATE");
                //停用日期
                string enddate = json_formdata.Value <string>("ENDDATE");

                string formdata = "{\"CODE\":\"" + code + "\",\"BOOKATTRIBUTE\":\"" + BOOKATTRIBUTE + "\",\"ENABLED\":\"" + ENABLED + "\",\"STARTDATE\":\"" + startdate + "\",\"ENDDATE\":\"" + enddate + "\",\"ISMODEL\":\"" + ISMODEL + "\"," +
                                  "\"BUSIUNIT\":\"" + BUSIUNIT + "\",\"RECEIVEUNIT\":\"" + RECEIVEUNIT + "\",\"TRADE\":\"" + TRADE + "\",\"EXEMPTING\":\"" + EXEMPTING + "\",\"REMARK\":\"" + REMARK + "\"}";
                //string formdata = sw.importValue(json_formdata, table, stringList);
                JObject json = (JObject)JsonConvert.DeserializeObject(formdata);
                if (bc.check_sys_recordinfo(json).Tables[0].Rows.Count > 0 || string.IsNullOrEmpty(json.Value <string>("CODE")))
                {
                    errorlines.Add(i + 2);
                }
                else
                {
                    bc.insert_sys_recordinfo(json);
                    count = count + 1;
                }
                stringList.Clear();
            }
            successinsert.Add(count);
            returndic.Add(1, successinsert);
            returndic.Add(2, errorlines);
            return(returndic);
        }
Пример #2
0
        private void save(string formdata)
        {
            JObject json = (JObject)JsonConvert.DeserializeObject(formdata);

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

            if (string.IsNullOrEmpty(json.Value <string>("ID")))
            {
                //查询是否有重复值
                if (json.Value <string>("ENABLED") == "1")
                {
                    if (br.check_sys_recordinfo(json).Tables[0].Rows.Count > 0)
                    {
                        response = "{\"success\":\"4\"}";
                    }
                    else
                    {
                        int i = br.insert_sys_recordinfo(json);
                        response = "{\"success\":" + (i > 0 ? "true" : "false") + "}";
                    }
                }
                else
                {
                    int i = br.insert_sys_recordinfo(json);
                    response = "{\"success\":" + (i > 0 ? "true" : "false") + "}";
                }
            }
            else
            {
                //更新
                if (json.Value <string>("ENABLED") == "1")
                {
                    if (br.update_check_sys_recordinfo(json).Rows.Count > 0)
                    {
                        //当数据有重复时success返回值为4
                        response = "{\"success\":\"4\"}";
                    }
                    else
                    {
                        DataTable dt = br.Before_Change(json);
                        int       i  = br.update_sys_recordinfo(json);
                        if (i > 0)
                        {
                            string content = bm.getrecordinfor(dt, json);
                            br.saveChanges_recordinfo(json, content);
                            response = "{\"success\":" + (i > 0 ? "true" : "false") + "}";
                        }
                    }
                }
                else
                {
                    DataTable dt = br.Before_Change(json);
                    int       i  = br.update_sys_recordinfo(json);
                    if (i > 0)
                    {
                        string content = bm.getrecordinfor(dt, json);
                        br.saveChanges_recordinfo(json, content);
                        response = "{\"success\":" + (i > 0 ? "true" : "false") + "}";
                    }
                }
            }

            Response.Write(response);
            Response.End();
        }