Ejemplo n.º 1
0
 /// <summary>
 /// 系统信息初始化
 /// </summary>
 public void InitInfo()
 {
     try
     {
         //BaseVariable.InitXmlVar();//初始化基础变量
         XmlHelper xml = new XmlHelper();
         BaseVariable.RequestURL = xml.SelectValue("/Root/Server/APIURL");
         bool IsRunFirst = xml.SelectValue("/Root/Local/IsRunFirst") == "0" ? false : true;//判断是否是第一次运行
         if (IsRunFirst)
         {
             bool IsCreateTable = false;
             if (LocalDbDAL.CreateDB())
             {
                 IsCreateTable = LocalDbDAL.CreateTable();
             }
             if (IsCreateTable)
             {
                 xml.UpdateInnerText("/Root/Local/DbIsCreated", "1");
             }
             //初始化xml信息
             //创建数据库
             //创建数据表
             xml.UpdateInnerText("/Root/Local/IsRunFirst", "0");
         }
         BaseVariable.RequestURL = xml.SelectValue("/Root/Server/APIURL");
         BaseVariable.IsRunFirst = IsRunFirst;
         this.txtUser.Text       = xml.SelectValue("/Root/User/UserID");
         this.txtPwd.Text        = xml.SelectValue("/Root/User/UserPwd");
     }
     catch (Exception ex)
     {
         CLog.WriteErrLog(ex.Message);
     }
 }
Ejemplo n.º 2
0
 /// <summary>
 /// 上传零件记录
 /// </summary>
 public static void UploadMaterialTable()
 {
     try
     {
         string sql = string.Format("SELECT * FROM {0}", BaseVariable.ResultTableName);
         //获取当前产品的数据表
         DataTable table = LocalDbDAL.GetDataTable(sql);
         if (table == null || table.Rows.Count == 0)
         {
             return;
         }
         //向服务器发送请求,数据上传并返回上传成功的数据TID
         string IDs = ResultDAL.Upload(BaseVariable.DeviceEntity.ProductType, BaseVariable.ResultTableName, table);
         if (!string.IsNullOrEmpty(IDs))
         {
             sql = string.Format("DELETE FROM {0} WHERE tid IN ({1});", BaseVariable.ResultTableName, IDs);
             LocalDbDAL.ExecuteSql(sql);//上传后删除本地数据
             CLog.WriteStationLog("Sys", "UploadMaterialTable:TID->{" + IDs + "},Time:{" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "}");
             //string[] str = IDs.Split(',');
         }
     }
     catch (Exception ex)
     {
         CLog.WriteErrLog(ex.Message);
     }
 }
Ejemplo n.º 3
0
        /// <summary>
        /// 加载数据
        /// </summary>
        public void LoadData()
        {
            try
            {
                string    sql   = string.Format("SELECT DISTINCT(materialcode),materialname,CASE WHEN batchnum > 0 then batchnum ELSE 0 END batchnum FROM ProductBomInfo WHERE TraceType='{0}' AND ProductType = '{1}' ORDER BY materialcode ASC", "批次追溯", BaseVariable.DeviceEntity.ProductType);
                DataTable table = LocalDbDAL.GetDataTable(sql);

                if (table == null || table.Rows.Count < 1)
                {
                    MaterialInfoList = null;
                    return;
                }
                this.cmbMaterialCode.Items.Add("--- 请选择 ---");
                foreach (DataRow row in table.Rows)
                {
                    BatchNoMDL model = new BatchNoMDL()
                    {
                        MaterialCode = row["MaterialCode"].ToString(),
                        MaterialName = row["MaterialName"].ToString(),
                        BatchNum     = int.Parse(row["BatchNum"].ToString())
                    };
                    if (!MaterialInfoList.ContainsKey(model.MaterialCode))
                    {
                        this.cmbMaterialCode.Items.Add(model.MaterialCode);
                        MaterialInfoList.Add(model.MaterialCode, model);
                    }
                }
            }
            catch (Exception ex)
            {
                CLog.WriteErrLog("[Frmbatch.LoadInfo]" + ex.Message);
            }
        }
Ejemplo n.º 4
0
 /// <summary>
 /// 上传零件记录
 /// </summary>
 private void UploadTable()
 {
     this.Invoke((EventHandler) delegate
     {
         try
         {
             Cursor.Current      = Cursors.WaitCursor;
             progressBar.Value   = 0;
             progressBar.Maximum = 1;
             string sql          = string.Format("SELECT * FROM {0}", BaseVariable.ResultTableName);
             //获取当前产品的数据表
             DataTable table = LocalDbDAL.GetDataTable(sql);
             if (table == null || table.Rows.Count < 1)
             {
                 return;
             }
             //向服务器发送请求,数据上传并返回上传成功的数据TID
             string IDs = ResultDAL.Upload(BaseVariable.DeviceEntity.ProductType, BaseVariable.ResultTableName, table);
             if (!string.IsNullOrEmpty(IDs))
             {
                 sql = string.Format("DELETE FROM {0} WHERE tid IN ({1});", BaseVariable.ResultTableName, IDs);
                 LocalDbDAL.ExecuteSql(sql);//上传后删除本地数据
                 string [] str = IDs.Split(',');
                 uploadnum    += str.Length;
             }
             ProgressTip(1);//更新进度
             Cursor.Current = Cursors.Default;
         }
         catch (Exception ex)
         {
             CLog.WriteErrLog(ex.Message);
         }
     });
 }
Ejemplo n.º 5
0
 /// <summary>
 /// 整合追溯信息为Hashtable
 /// </summary>
 /// <returns></returns>
 private Hashtable GetHashtable()
 {
     try
     {
         string    sql   = string.Format("SELECT * FROM (SELECT t.* FROM (SELECT b.*, m.tablename, m.fieldname FROM productinfo p, productbominfo b, materialfield m WHERE p.productcode = b.productcode AND p.producttype = b.producttype AND b.materialcode = m.materialcode AND m.tablename='{0}') t LEFT JOIN batchno n ON t.materialcode = n.materialcode) t WHERE  productcode='{1}' AND producttype='{2}' AND tracetype in({3});", BaseVariable.ResultTableName, this.productModel.ProductCode, BaseVariable.DeviceEntity.ProductType, "'扫描追溯'");
         DataTable table = LocalDbDAL.GetDataTable(sql);
         if (table != null && table.Rows.Count > 0)
         {
             Hashtable HTSelect = MaterialBomDAL.GetList(table);
             Hashtable HTResult = new Hashtable();
             foreach (var item in RequestParam)
             {
                 if (HTSelect.ContainsKey(item.Key))
                 {
                     MaterialBomMDL model = HTSelect[item.Key] as MaterialBomMDL;
                     model.BatchBarCode = item.Value;
                     HTResult.Add(item.Key, model);
                 }
             }
             return(HTResult);
         }
         return(null);
     }
     catch (Exception ex)
     {
         CLog.WriteErrLog(ex.Message);
         return(null);
     }
 }
Ejemplo n.º 6
0
        /// <summary>
        /// 封装更新字段
        /// </summary>
        /// <param name="IsRemote"></param>
        /// <returns></returns>
        private string DataExistToDb(bool IsRemote)
        {
            string    sql        = string.Format("SELECT * FROM materialfield WHERE materialcode in(SELECT materialcode FROM productbominfo WHERE producttype='{0}' AND productcode='{1}')", BaseVariable.DeviceEntity.ProductType, resultModel.productcode);
            DataTable fieldTable = null;

            if (IsRemote)
            {
                fieldTable = CommonDAL.GetDataTable(sql);        //远程获取
            }
            else
            {
                fieldTable = LocalDbDAL.GetDataTable(sql);        //本地获取
            }
            sql = "update pedalresult set";
            #region 对应更新字段
            if (fieldTable != null && fieldTable.Rows.Count > 0)
            {
                foreach (DataRow fieldRow in fieldTable.Rows)
                {
                    string filed = fieldRow["FieldName"].ToString();
                    #region 对应更新字段
                    switch (filed)
                    {
                    //踏板总成
                    case "pedalassycode":
                        sql += string.Format("pedalassycode='{0}',", resultModel.pedalassycode);
                        break;

                    //油门踏板
                    case "accelpedalcode":
                        sql += string.Format("accelpedalcode='{0}',", resultModel.accelpedalcode);
                        break;

                    //离合器把手批次号
                    case "cluthhandlebatchno":
                        sql += string.Format("cluthhandlebatchno='{0}',", resultModel.cluthhandlebatchno);
                        break;

                    //螺栓批次号
                    case "boltbatchno":
                        sql += string.Format("boltbatchno='{0}',", resultModel.boltbatchno);
                        break;

                    //螺母批次号
                    case "nutbatchno":
                        sql += string.Format("nutbatchno='{0}',", resultModel.nutbatchno);
                        break;
                    }
                    #endregion
                }
            }
            #endregion
            sql  = sql.Substring(0, sql.LastIndexOf(','));
            sql += string.Format(" where tid={0}", resultModel.tid);
            return(sql);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// 加载 ListView 数据
        /// </summary>
        public void InitListView()
        {
            try
            {
                this.lvMaterial.Items.Clear();
                this.lblProductCode.Text = this.productModel.ProductCode;
                this.lblTitle.Text       = "返修-" + this.productModel.ProductName;
                this.scantype            = ScanType.MATERIALCODE;
                //获取BOM表的信息

                /**
                 * 一次获取当前产品所有BOM信息
                 * 2014.11.30 By xudy
                 */
                string    sql   = string.Format("SELECT p.*,m.fieldname FROM `productbominfo` p INNER JOIN materialfield m ON p.materialcode=m.materialcode WHERE producttype='{0}' AND productcode='{1}' AND tracetype IN({2})", BaseVariable.DeviceEntity.ProductType, this.productModel.ProductCode, "'扫描追溯','批次追溯'");
                DataTable table = LocalDbDAL.GetDataTable(sql);
                if (table != null && table.Rows.Count > 0)
                {
                    int index = 0;
                    foreach (DataRow row in table.Rows)
                    {
                        ListViewItem item = new ListViewItem(row["materialcode"].ToString()); //材料条码:0
                        item.SubItems.Add(row["materialname"].ToString());                    //:1
                        item.SubItems.Add("");                                                //:2
                        item.SubItems.Add(row["featurecode"].ToString());                     //特征码:3
                        item.SubItems.Add(row["featureindex"].ToString());                    //特征位:4
                        item.SubItems.Add(row["fieldname"].ToString());                       //字段民称:5
                        item.SubItems.Add(row["tracetype"].ToString());                       //追溯类型:6
                        if (index % 2 == 0)
                        {
                            item.BackColor = Color.Gainsboro;//偶数背景色淡灰色
                        }
                        else
                        {
                            item.BackColor = Color.Silver; //奇数背景色为银色
                        }
                        item.ForeColor = Color.Black;      //字体颜色为黑色
                        this.lvMaterial.Items.Add(item);
                        index++;
                    }
                }
                else
                {
                    this.lblTip.Text = "当前型号没有追溯零件";
                }
            }
            catch (Exception ex)
            {
                CLog.WriteErrLog(ex.Message);
            }
        }
Ejemplo n.º 8
0
        /// <summary>
        /// 组装SQL语句
        /// </summary>
        /// <param name="IsExit"></param>
        /// <param name="tid"></param>
        /// <returns></returns>
        private string AssembleSqlCode(Hashtable ParamHTList)
        {
            //查询合件是否存在
            object obj = LocalDbDAL.ExecuteScaler(string.Format("SELECT tid FROM {0} WHERE barcode ='{1}';", BaseVariable.ResultTableName, this.lblHJCode.Text));
            long   TID = obj != null && obj.ToString() != "0" ? long.Parse(obj.ToString()) : 0;
            string sql = "";

            if (TID != 0)
            {
                sql += string.Format("update {0} set ", BaseVariable.ResultTableName);
                #region 对应更新字段
                if (ParamHTList != null && ParamHTList.Count > 0)
                {
                    foreach (DictionaryEntry Entry in ParamHTList)
                    {
                        MaterialBomMDL model = Entry.Value as MaterialBomMDL;
                        if (!string.IsNullOrEmpty(model.BatchBarCode))
                        {
                            sql += string.Format("{0}='{1}',", model.FieldName, model.BatchBarCode);
                        }
                    }
                }
                #endregion
                sql += string.Format("userid='{0}',stationid='{1}',scantype='{2}'", BaseVariable.UserEntity.UserID, BaseVariable.DeviceEntity.StationID, CurrnetScanType);
                sql += string.Format(" where tid={0}", TID);
            }
            else
            {
                string field  = "";
                string values = "";
                #region 对应更新字段
                if (ParamHTList != null && ParamHTList.Count > 0)
                {
                    foreach (DictionaryEntry Entry in ParamHTList)
                    {
                        MaterialBomMDL model = Entry.Value as MaterialBomMDL;
                        if (!string.IsNullOrEmpty(model.BatchBarCode))
                        {
                            field  += model.FieldName + ",";
                            values += string.Format("'{0}',", model.BatchBarCode);
                        }
                    }
                }
                #endregion
                field  += "barcode,productcode,userid,stationid,scantype";
                values += string.Format("'{0}','{1}','{2}','{3}','{4}'", this.lblHJCode.Text, this.productModel.ProductCode, BaseVariable.UserEntity.UserID, BaseVariable.DeviceEntity.StationID, CurrnetScanType);
                sql    += string.Format("insert into {0}({1}) values({2});", BaseVariable.ResultTableName, field, values);
            }
            return(sql);
        }
Ejemplo n.º 9
0
 /// <summary>
 /// 获取批次的记录条数
 /// </summary>
 /// <returns></returns>
 public static int GetBatchCount()
 {
     try
     {
         string sql   = "SELECT COUNT(tid) FROM BatchNo;";
         int    count = LocalDbDAL.ExecuteScaler(sql) == null && LocalDbDAL.ExecuteScaler(sql).ToString() == "0" ? (int)LocalDbDAL.ExecuteScaler(sql) : 0;
         return(count);
     }
     catch (Exception ex)
     {
         CLog.WriteErrLog(ex.Message);
         return(0);
     }
 }
Ejemplo n.º 10
0
 /// <summary>
 /// 获取当前产品的记录条数
 /// </summary>
 /// <returns></returns>
 public static int GetMarterialCount()
 {
     try
     {
         string sql   = string.Format("SELECT COUNT(tid) FROM '{0}';", BaseVariable.ResultTableName);
         int    count = LocalDbDAL.ExecuteScaler(sql) == null && LocalDbDAL.ExecuteScaler(sql).ToString() == "0" ? (int)LocalDbDAL.ExecuteScaler(sql) : 0;
         return(count);
     }
     catch (Exception ex)
     {
         CLog.WriteErrLog(ex.Message);
         return(0);
     }
 }
Ejemplo n.º 11
0
 /// <summary>
 /// 添加批量追溯信息
 /// </summary>
 private void GetBatchInfoToParam()
 {
     #region 添加批量追溯信息
     if (BaseVariable.DeviceEntity.ProductType != "前桥" || BaseVariable.DeviceEntity.ProductType != "后桥")
     {
         string    sql   = string.Format("SELECT tid,producttype,productcode,materialcode,materialname,materialnum,tracetype,fieldname,batchno FROM (SELECT t.*,n.batchno batchno FROM (SELECT b.*, m.tablename, m.fieldname FROM productinfo p, productbominfo b, materialfield m WHERE p.productcode = b.productcode AND p.producttype = b.producttype AND b.materialcode = m.materialcode AND m.tablename='{0}') t LEFT JOIN batchno n ON t.materialcode = n.materialcode) t WHERE  productcode='{1}' AND producttype='{2}' AND tracetype in({3});", BaseVariable.ResultTableName, this.productModel.ProductCode, BaseVariable.DeviceEntity.ProductType, "'批次追溯'");
         DataTable table = LocalDbDAL.GetDataTable(sql);
         if (table != null && table.Rows.Count > 0)
         {
             foreach (DataRow row in table.Rows)
             {
                 if (row["batchno"] != null && row["batchno"].ToString() != "")
                 {
                     RequestParam.Add(row["materialcode"].ToString(), row["batchno"].ToString());
                 }
             }
         }
     }
     #endregion
 }
Ejemplo n.º 12
0
        /// <summary>
        /// 获取扫描追溯BOM表的信息
        /// </summary>
        private void InitListView()
        {
            this.lvMaterial.Items.Clear();

            string    sql   = string.Format("SELECT p.*,m.fieldname FROM `productbominfo` p INNER JOIN materialfield m ON p.materialcode=m.materialcode WHERE producttype='{0}' AND productcode='{1}' AND tracetype IN({2})", BaseVariable.DeviceEntity.ProductType, this.productModel.ProductCode, "'扫描追溯'");
            DataTable table = LocalDbDAL.GetDataTable(sql);

            if (table != null && table.Rows.Count > 0)
            {
                int index = 0;
                foreach (DataRow row in table.Rows)
                {
                    ListViewItem item = new ListViewItem(row["materialcode"].ToString());//材料条码
                    item.SubItems.Add("");
                    item.SubItems.Add(row["materialnum"].ToString());
                    item.SubItems.Add("0");
                    item.SubItems.Add(row["materialname"].ToString());
                    item.SubItems.Add(row["featurecode"].ToString());  //特征码
                    item.SubItems.Add(row["featureindex"].ToString()); //特征位
                    item.SubItems.Add(row["fieldname"].ToString());    //字段民称
                    if (index % 2 == 0)
                    {
                        item.BackColor = Color.Gainsboro;//偶数背景色淡灰色
                    }
                    else
                    {
                        item.BackColor = Color.Silver; //奇数背景色为银色
                    }
                    item.ForeColor = Color.Black;      //字体颜色为黑色
                    this.lvMaterial.Items.Add(item);
                    index++;
                }
                IsHjScan = true;//扫描合件标示为true
            }
            else
            {
                this.Tip("当前型号没有扫描追溯零件");
            }
        }
Ejemplo n.º 13
0
        /// <summary>
        /// 下载数据
        /// </summary>
        private void Download()
        {
            try
            {
                //0.清空表
                StringBuilder StrSql = new StringBuilder();
                StrSql.AppendLine("DELETE FROM userinfo;");
                StrSql.AppendLine("DELETE FROM deviceinfo;");
                StrSql.AppendLine("DELETE FROM productinfo;");
                StrSql.AppendLine("DELETE FROM productbominfo;");
                StrSql.AppendLine("DELETE FROM materialfield;");
                bool rst = LocalDbDAL.ExecuteSqlTran(StrSql.ToString());

                //1.用户表
                TitleTip("下载用户表……");
                DownloadUser();
                //2.设备表
                TitleTip("下载设备表……");
                DownloadDevice();
                //3.产品表
                TitleTip("下载产品表……");
                DownloadProduct();
                //4.bom表
                TitleTip("下载BOM表……");
                DownloadBOM();
                //5.材料字段表
                TitleTip("下载材料字段……");
                DownloadMaterialField();
                TitleTip("下载数据完毕");
            }
            catch (Exception ex)
            {
                CLog.WriteErrLog(ex.Message);
            }
            finally
            {
                CloseForm();
            }
        }
Ejemplo n.º 14
0
        /// <summary>
        /// 初始化特征码集合
        /// </summary>
        /// <returns></returns>
        public static bool InitFeatureCode()
        {
            string    sql   = string.Format("SELECT DISTINCT(b.materialcode),b.materialname,p.productcode,p.producttype,p.featurecode,p.featureindex FROM productbominfo  b LEFT JOIN productinfo p ON b.productcode=p.productcode WHERE p.producttype='{0}'", BaseVariable.DeviceEntity.ProductType);
            DataTable table = LocalDbDAL.GetDataTable(sql);

            if (table != null && table.Rows.Count > 0)
            {
                FeatureCodeDict = new Dictionary <string, List <string> >();
                FeatureIndexSet = new Hashtable();
                foreach (DataRow row in table.Rows)
                {
                    string        c    = row["materialcode"].ToString();
                    string        f    = row["featurecode"].ToString();
                    string        i    = row["featureindex"].ToString();
                    List <string> list = new List <string>();

                    if (FeatureCodeDict.ContainsKey(c))
                    {
                        list = FeatureCodeDict[c];
                        FeatureCodeDict.Remove(c);
                    }

                    // 将特征码添加特征码的列表
                    list.Add(f);
                    // 添加零件对应特征码的列表
                    FeatureCodeDict.Add(c, list);

                    // 添加特征码对应的索引
                    //if (!FeatureIndexSet.ContainsKey(f))
                    //{
                    //    FeatureIndexSet.Add(f + "_" + c, i);
                    //}
                }
                return(true);
            }
            return(false);
        }
Ejemplo n.º 15
0
        /// <summary>
        /// 保存数据到本地
        /// </summary>
        /// <returns></returns>
        private bool SaveToLocal()
        {
            string sql = "";

            try
            {
                //1.整合追溯信息
                Hashtable HTResult = GetHashtable();
                if (HTResult == null && HTResult.Count < 1)
                {
                    return(false);
                }
                //2.组装SQL语句
                sql = AssembleSqlCode(HTResult);
                bool flag = LocalDbDAL.ExecuteSql(sql);
                return(flag);
            }
            catch (Exception ex)
            {
                CLog.WriteErrLog(ex.Message);
                CLog.WriteStationLog("DataErr", sql);
                return(false);
            }
        }
        /// <summary>
        /// 封装更新字段
        /// </summary>
        /// <param name="IsRemote"></param>
        /// <returns></returns>
        private string DataExistToDb(bool IsRemote)
        {
            string    sql        = string.Format("SELECT * FROM materialfield WHERE materialcode in(SELECT materialcode FROM productbominfo WHERE producttype='{0}' AND productcode='{1}')", BaseVariable.DeviceEntity.ProductType, resultModel.productcode);
            DataTable fieldTable = null;

            if (IsRemote)
            {
                fieldTable = CommonDAL.GetDataTable(sql);        //远程获取
            }
            else
            {
                fieldTable = LocalDbDAL.GetDataTable(sql);        //本地获取
            }
            sql = "";
            #region 对应更新字段
            if (fieldTable != null && fieldTable.Rows.Count > 0)
            {
                foreach (DataRow fieldRow in fieldTable.Rows)
                {
                    string filed = fieldRow["FieldName"].ToString();
                    #region 对应更新字段
                    switch (filed)
                    {
                    //制动泵编码
                    case "brakepumpcode":
                        sql += string.Format("brakepumpcode='{0}',", resultModel.brakepumpcode);
                        break;

                    //密封垫批次号
                    case "gasketbatchno":
                        sql += string.Format("gasketbatchno='{0}',", resultModel.gasketbatchno);
                        break;

                    //六角(法兰面)螺母
                    case "hexagonalnutbatchno":
                        sql += string.Format("hexagonalnutbatchno='{0}',", resultModel.hexagonalnutbatchno);
                        break;

                    //压力传感器批次号
                    case "pressuresensorbatchno":
                        sql += string.Format("pressuresensorbatchno='{0}',", resultModel.pressuresensorbatchno);
                        break;

                    //消音器(制动泵隔音垫)
                    case "silencerbatchno":
                        sql += string.Format("silencerbatchno='{0}',", resultModel.silencerbatchno);
                        break;

                    //结合管(制动连接管)
                    case "connectingpipe":
                        sql += string.Format("connectingpipe='{0}',", resultModel.connectingpipe);
                        break;

                    //助力器制动泵支架
                    case "boosterbrakepumpbracket":
                        sql += string.Format("boosterbrakepumpbracket='{0}',", resultModel.boosterbrakepumpbracket);
                        break;
                    }
                    #endregion
                }
            }
            #endregion
            sql  = sql.Substring(0, sql.LastIndexOf(','));
            sql += string.Format(" where tid={0}", resultModel.tid);
            return(sql);
        }
Ejemplo n.º 17
0
        /// <summary>
        /// 获取当前条码是否存在
        /// 1.合件号;2.零件号(是一一追溯的零件)
        /// </summary>
        /// <param name="type">1:合件,2:零件</param>
        /// <param name="barcode">要验证的条码</param>
        /// <param name="materialfiled">字段名</param>
        public bool ValidateScanIsExist(int Type, string BarCode, string Filed)
        {
            Stopwatch existWatch = new Stopwatch();

            try
            {
                /*
                 * 人物:xudy
                 * 时间:2015-01-18
                 * 内容:修改了条件,讲userid、barcode换为tid
                 */
                if (Opt.GlobalNetStatus())//从服务器获取数据
                {
                    existWatch.Start();
                    //string requestUrl = BaseVariable.RequestURL + "Result.ashx";
                    //Dictionary<string, object> dict = new Dictionary<string, object>();
                    //dict.Add("do", "validate");
                    //dict.Add("Type", Type);
                    //dict.Add("TableName", BaseVariable.ResultTableName);
                    //dict.Add("BarCode", BarCode);
                    //dict.Add("ProductCode", this.productModel.ProductCode);
                    //dict.Add("Filed", Filed);

                    //string str = Http.POST(requestUrl, dict);
                    //var obj = JsonHelper.JsonDeSerializer<ReturnInfo>(str);
                    //ReturnInfo ReturnData = (ReturnInfo)obj;
                    //if (ReturnData != null && ReturnData.Code == "1")
                    //{
                    //    return true;
                    //}

                    return(ResultDAL.Validate(BaseVariable.ResultTableName, BarCode, this.productModel.ProductCode, Type, Filed));
                }
                else//从本地获取数据
                {
                    string sql = "";
                    switch (Type)
                    {
                    case 1:    //合件
                        sql = string.Format("select tid from {0} where barcode='{1}' and productcode='{2}'", BaseVariable.ResultTableName, BarCode, this.productModel.ProductCode);
                        break;

                    case 2:    //子件
                        sql = string.Format("select tid from {0} where {2}='{1}'", BaseVariable.ResultTableName, BarCode, Filed);
                        break;
                    }
                    object obj = LocalDbDAL.ExecuteScaler(sql);
                    if (obj != null && !string.IsNullOrEmpty(obj.ToString()))
                    {
                        return(true);
                    }
                }
                return(false);
            }
            catch (Exception ex)
            {
                CLog.WriteErrLog(ex.Message);
                return(false);
            }
            finally
            {
                LogType ty = LogType.Y1;
                switch (Type)
                {
                case 1:        //合件
                    ty = LogType.Y1;
                    break;

                case 2:        //子件
                    ty = LogType.Y2;
                    break;
                }
                this.WirteTimeSpanLog(new TimeSpan(0, 0, 0, 0, (int)existWatch.ElapsedMilliseconds), ty);
                existWatch.Stop();
            }
        }
Ejemplo n.º 18
0
        /// <summary>
        /// 防错追溯,将信息添加到数据库
        /// </summary>
        private void ScanResultToDb()
        {
            try
            {
                if (resultModel != null)
                {
                    bool rst = false;
                    if (!BaseVariable.NetworkStatus || !BaseVariable.ServerStatus)        //离线状态
                    {
                        resultModel.createtime = DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
                        PedalResultMDL IsExistLocal = lResultDAL.GetModel(string.Format("barcode='{0}' and productcode='{1}'", this.txtHJCode.Text, this.txtProductCode.Text));
                        if (IsExistLocal != null && !IsExistLocal.tid.ToString().Equals("0"))
                        {
                            resultModel.tid = IsExistLocal.tid;
                            string sql = DataExistToDb(false);
                            rst = LocalDbDAL.ExecuteSql(sql);        //存到本地数据库
                        }
                        else
                        {
                            rst = lResultDAL.Add(resultModel);        //添加到本地数据库
                        }
                    }
                    else        //在线状态
                    {
                        //添加批量追溯信息
                        GetBatchInfoToModel();

                        //同步到数据库:在没有同步到远程数据库时记录到本地数据库
                        #region  步到数据库
                        resultModel.createtime = DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
                        rst = false;        //更新到远程服务器数据库是否成功
                        PedalResultMDL IsExistRomote = resultDAL.GetModel(string.Format("barcode='{0}' and productcode='{1}'", this.txtHJCode.Text, this.txtProductCode.Text));
                        //更新到远程服务器数据库
                        if (IsExistRomote != null && !IsExistRomote.tid.ToString().Equals("0"))
                        {
                            resultModel.tid        = IsExistRomote.tid;
                            resultModel.createtime = DateTime.Parse(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
                            //封装更新字段
                            string sql = DataExistToDb(true);
                            //sql += string.Format("CreateTime='{0}',", resultModel.CreateTime);
                            rst = CommonDAL.ExecuteSql(sql, null);        //存到远程服务器数据库
                        }
                        else
                        {
                            rst = resultDAL.Add(resultModel);        //添加到远程服务器数据库
                        }
                        //更新到本地数据库
                        //rst = false;
                        if (!rst)
                        {
                            PedalResultMDL IsExistLocal = lResultDAL.GetModel(string.Format("barcode='{0}' and productcode='{1}'", this.txtHJCode.Text, this.txtProductCode.Text));
                            if (IsExistLocal != null && !IsExistLocal.tid.ToString().Equals("0"))
                            {
                                resultModel.tid = IsExistLocal.tid;
                                string sql = DataExistToDb(true);
                                rst = LocalDbDAL.ExecuteSql(sql);        //存到本地数据库
                            }
                            else
                            {
                                rst = lResultDAL.Add(resultModel);        //添加到本地数据库
                            }
                        }
                        //批次材料数量更新
                        foreach (DictionaryEntry item in RemoteMaterialHT)        // 遍历哈希表
                        {
                            string            code = item.Key.ToString();
                            ProductBomInfoMDL obj  = item.Value as ProductBomInfoMDL;
                            //var obj = item.Value;
                            BatchNoMDL model = LocalMaterialHT[code] as BatchNoMDL;
                            model.StockNum -= obj.MaterialNum;
                            batchDAL.Update(model);        //更新数据
                        }
                        #endregion
                        if (rst)
                        {
                            this.lblOK.Text      = "OK";
                            this.lblOK.ForeColor = Color.Green;
                        }
                        else
                        {
                            this.lblOK.Text      = "NG";
                            this.lblOK.ForeColor = Color.Red;
                        }
                        BatchChangeTip();        //批次数量提示
                    }
                }
                else
                {
                    this.Tip("记录错误");
                }
            }
            catch (Exception ex)
            {
                CLog.WriteErrLog("[FrmScan.ScanResultToDB]" + ex.Message);
            }
        }