예제 #1
0
        /// <summary>
        /// DataTable 转对象
        /// </summary>
        /// <param name="sql"></param>
        /// <returns></returns>
        public static MarerialInfoTable ConvertDataTableToModel(string sql)
        {
            error = string.Empty;
            DataTable         dt           = SqlHelper.GetTable(sql, ref error);
            DataRow           dr           = dt.Rows[0];
            MarerialInfoTable marerialinfo = new MarerialInfoTable();

            marerialinfo.MaterialNumber   = dr["MaterialNumber"] == null ? "" : dr["MaterialNumber"].ToString();
            marerialinfo.MaterialName     = dr["MaterialName"] == null ? "" : dr["MaterialName"].ToString();
            marerialinfo.Description      = dr["Description"] == null ? "" : dr["Description"].ToString();
            marerialinfo.Kind             = dr["Kind"] == null ? "" : dr["Kind"].ToString();
            marerialinfo.Type             = dr["Type"] == null ? "" : dr["Type"].ToString();
            marerialinfo.Brand            = dr["Brand"] == null ? "" : dr["Brand"].ToString();
            marerialinfo.StockSafeQty     = Convert.ToInt32(dr["StockSafeQty"] == null ? "" : dr["StockSafeQty"].ToString());
            marerialinfo.ProcurementPrice = Convert.ToDecimal(dr["ProcurementPrice"] == null ? "" : dr["ProcurementPrice"].ToString());
            marerialinfo.MaterialPosition = dr["MaterialPosition"] == null ? "" : dr["MaterialPosition"].ToString();
            marerialinfo.MinPacking       = dr["MinPacking"] == null ? "" : dr["MinPacking"].ToString();
            marerialinfo.MinOrderQty      = dr["MinOrderQty"] == null ? "" : dr["MinOrderQty"].ToString();
            marerialinfo.ScrapPosition    = dr["ScrapPosition"] == null ? "" : dr["ScrapPosition"].ToString();
            marerialinfo.Remark           = dr["Remark"] == null ? "" : dr["Remark"].ToString();
            marerialinfo.Cargo            = dr["Cargo"] == null ? "" : dr["Cargo"].ToString();
            marerialinfo.SixStockSafeQty  = dr["SixStockSafeQty"] == null ? "" : dr["SixStockSafeQty"].ToString();
            marerialinfo.CargoType        = dr["CargoType"] == null ? "" : dr["CargoType"].ToString();
            marerialinfo.NumberProperties = dr["NumberProperties"] == null ? "" : dr["NumberProperties"].ToString();
            marerialinfo.Unit             = dr["Unit"] == null ? "" : dr["Unit"].ToString();
            return(marerialinfo);
        }
예제 #2
0
        /// <summary>
        /// 编辑原材料信息
        /// </summary>
        /// <param name="user"></param>
        /// <param name="error"></param>
        /// <returns></returns>
        public static bool EditMarerialInfoTable(MarerialInfoTable maretialinfotable, ref string error)
        {
            if (!IsExit(maretialinfotable.MaterialNumber))
            {
                error = "不存在该原材料编号!请重新填写!";
                return(false);
            }
            List <string> list = new List <string>();

            sql = string.Format(@" update MarerialInfoTable set MaterialName='{0}',
Description='{1}',Kind='{2}',Type='{3}',Brand='{4}',StockSafeQty={5},ProcurementPrice='{6}'
,MaterialPosition='{7}',MinPacking='{8}',
MinOrderQty='{9}',ScrapPosition='{10}',Remark='{11}' ,CargoType='{13}',NumberProperties='{14}',Unit='{15}'
where MaterialNumber='{12}'", maretialinfotable.MaterialName,
                                maretialinfotable.Description, maretialinfotable.Kind, maretialinfotable.Type,
                                maretialinfotable.Brand, maretialinfotable.StockSafeQty, maretialinfotable.ProcurementPrice,
                                maretialinfotable.MaterialPosition, maretialinfotable.MinPacking, maretialinfotable.MinOrderQty,
                                maretialinfotable.ScrapPosition, maretialinfotable.Remark, maretialinfotable.MaterialNumber, maretialinfotable.CargoType, maretialinfotable.NumberProperties, maretialinfotable.Unit);
            list.Add(sql);
            sql = string.Format(@" update Product  set CostPrice =(select sum(bom.SingleDose*mit.ProcurementPrice ) from BOMInfo bom 
inner join MarerialInfoTable mit on bom.MaterialNumber =mit.MaterialNumber
 where bom.ProductNumber =p.ProductNumber and bom.Version =p.Version 
 group by bom.ProductNumber , bom.Version  )  from Product  p 
inner join (
select ProductNumber ,Version  from BOMInfo  where  MaterialNumber  ='{0}') t on 
p.ProductNumber=t.ProductNumber  and p.Version =t.Version ", maretialinfotable.MaterialNumber);
            list.Add(sql);
            return(SqlHelper.BatchExecuteSql(list, ref error));
        }
        private void LoadPage()
        {
            string sql   = string.Empty;
            string error = string.Empty;

            //MarerialInfoTableManager.BindKind(drpKind);
            //ControlBindManager.BindDrp(" select type from MareriaType", drpType, "type", "type");
            //MarerialInfoTableManager.BindWarehouseName(drpMaterialPosition);
            if (ToolManager.CheckQueryString("Id"))
            {
                sql = string.Format(@" select * from MarerialInfoTable where MaterialNumber='{0}' ", Server.UrlDecode(ToolManager.GetQueryString("Id")));
                //sql = string.Format(@" select * from MarerialInfoTable where MaterialNumber='{0}' ", "test2");
                this.trMaterialNumber.Visible = false;
                MarerialInfoTable marerialinfotable = MarerialInfoTableManager.ConvertDataTableToModel(sql);
                this.txtMaterialNumber.Text   = marerialinfotable.MaterialNumber;
                this.txtMaterialName.Text     = marerialinfotable.MaterialName;
                this.txtDescription.Text      = marerialinfotable.Description;
                this.txtUnit.Text             = marerialinfotable.Unit;
                this.txtNumberProperties.Text = marerialinfotable.NumberProperties;
                this.txtKind.Text             = marerialinfotable.Kind;
                this.txtType.Text             = marerialinfotable.Type;
                //MarerialInfoTableManager.BindType(drpKind, drpType);
                //this.drpType.SelectedValue = marerialinfotable.Type;

                this.txtBrand.Text = marerialinfotable.Brand;
                //this.txtStockSafeQty.Text = marerialinfotable.StockSafeQty.ToString();
                this.txtProcurementPrice.Text = marerialinfotable.ProcurementPrice.ToString();

                this.drpMaterialPosition.SelectedValue = marerialinfotable.MaterialPosition;

                this.txtMinPacking.Text             = marerialinfotable.MinPacking;
                this.txtMinOrderQty.Text            = marerialinfotable.MinOrderQty;
                this.drpScrapPosition.SelectedValue = marerialinfotable.ScrapPosition;
                this.txtRemark.Text    = marerialinfotable.Remark;
                this.txtCargo.Text     = marerialinfotable.Cargo;
                this.txtCargoType.Text = marerialinfotable.CargoType;
                btnSubmit.Text         = "修改";
            }
        }
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            Regex r  = new Regex(@"[\u4e00-\u9fa5]+");
            Match mc = r.Match(txtMaterialNumber.Text.Trim());

            if (mc.Length != 0)
            {
                lbSubmit.Text = "注意:原材料编号禁止输入中文";
                lbSubmit.Focus();
                return;
            }
            string error = string.Empty;

            Model.MarerialInfoTable marerialinfotable = new MarerialInfoTable();
            marerialinfotable.MaterialNumber   = this.txtMaterialNumber.Text.Trim();
            marerialinfotable.MaterialName     = this.txtMaterialName.Text.Trim();
            marerialinfotable.Description      = this.txtDescription.Text.Trim();
            marerialinfotable.Kind             = this.txtKind.Text;
            marerialinfotable.Type             = this.txtType.Text;
            marerialinfotable.Brand            = this.txtBrand.Text.Trim();
            marerialinfotable.Cargo            = this.txtCargo.Text.Trim();
            marerialinfotable.CargoType        = this.txtCargoType.Text.Trim();
            marerialinfotable.NumberProperties = this.txtNumberProperties.Text.Trim();
            marerialinfotable.Unit             = this.txtUnit.Text.Trim();
            bool result = false;

            //if (this.txtStockSafeQty.Text.Trim().Length > 0 && this.txtProcurementPrice.Text.Trim().Length > 0)
            //{
            //    marerialinfotable.StockSafeQty = Convert.ToInt32(this.txtStockSafeQty.Text.Trim());
            //    marerialinfotable.ProcurementPrice = Convert.ToDecimal(this.txtProcurementPrice.Text.Trim());
            //}
            //else
            //{
            //    lbSubmit.Text = "原材料信息不完整!";
            //    return;
            //}
            marerialinfotable.StockSafeQty     = 0;
            marerialinfotable.ProcurementPrice = Convert.ToDecimal(this.txtProcurementPrice.Text.Trim());
            marerialinfotable.MaterialPosition = this.drpMaterialPosition.SelectedValue;
            marerialinfotable.MinPacking       = this.txtMinPacking.Text.Trim();
            marerialinfotable.MinOrderQty      = this.txtMinOrderQty.Text.Trim();
            marerialinfotable.ScrapPosition    = this.drpScrapPosition.SelectedValue.Trim();
            marerialinfotable.Remark           = this.txtRemark.Text.Trim();
            if (btnSubmit.Text.Equals("添加"))
            {
                result        = MarerialInfoTableManager.AddMarerialInfoTable(marerialinfotable, ref error);
                lbSubmit.Text = result == true ? "添加成功!" : "添加失败,原因:" + error;
                if (result)
                {
                    Tool.WriteLog(Tool.LogType.Operating, "增加原材料信息" + marerialinfotable.MaterialNumber, "增加成功");
                    ToolCode.Tool.ResetControl(this.Controls);
                    return;
                }
                else
                {
                    Tool.WriteLog(Tool.LogType.Operating, "增加原材料信息" + marerialinfotable.MaterialNumber, "增加失败!原因" + error);
                    return;
                }
            }
            else
            {
                result        = MarerialInfoTableManager.EditMarerialInfoTable(marerialinfotable, ref error);
                lbSubmit.Text = result == true ? "修改成功!" : "修改失败:原因:" + error;
                if (result)
                {
                    Tool.WriteLog(Tool.LogType.Operating, "编辑原材料信息" + marerialinfotable.MaterialNumber, "编辑成功");
                    return;
                }
                else
                {
                    Tool.WriteLog(Tool.LogType.Operating, "编辑原材料信息" + marerialinfotable.MaterialNumber, "编辑失败!原因" + error);
                    return;
                }
            }
        }