Example #1
0
 public bool Save(MaterielModel model)
 {
     using (DataProvider dp = new DataProvider())
     {
         var entity = data.GetMatById(dp, model.Id);
         if (entity == null)
         {
             model.IsDel      = false;
             model.CreateTime = DateTime.Now;
             dp.PM_Materiel.Add(Mapper.Map <PM_Materiel>(model));
         }
         else
         {
             entity.MaterielCode     = model.MaterielCode;
             entity.MaterielName     = model.MaterielName;
             entity.MaterielType     = model.MaterielType;
             entity.ResidualQuantity = model.ResidualQuantity;
             entity.Sort             = model.Sort;
             entity.IsEnabled        = model.IsEnabled;
             entity.UpdateUser       = model.UpdateUser;
             entity.UpdateTime       = DateTime.Now;
         }
         try
         {
             dp.SaveChanges();
             return(true);
         }
         catch
         {
             throw;
         }
     }
 }
Example #2
0
        private void button1_Click(object sender, EventArgs e)
        {
            int metering    = Convert.ToInt32(this.comboBox1.SelectedValue.ToString());
            int subMetering = Convert.ToInt32(this.comboBox2.SelectedValue.ToString());

            if (textBox1.Text == "" || textBox2.Text == "" || metering == 0 || (subMetering != 0 && textBox6.Text == ""))
            {
                MessageBox.Show("请填写必填项!");
                return;
            }

            string        type = this.comboBox3.Text;
            MaterielModel mm   = new MaterielModel(textBox1.Text, textBox2.Text, textBox3.Text, metering, checkBox1.Checked);

            if (textBox8.Text != "")
            {
                mm.Tax = Convert.ToDouble(textBox8.Text);
            }
            if (subMetering > 0)
            {
                mm.SubMetering = subMetering;
                mm.Conversion  = Convert.ToDouble(textBox6.Text);
            }
            if (this.category > 0)
            {
                mm.Catgegory = this.category;
            }
            if (type == "外购件")
            {
                mm.Type      = type;
                mm.NormPrice = Convert.ToDouble(numberbox11.TextNumber);
            }
            else
            {
                mm.Type = "自制件";
            }
            if (id > 0)
            {
                mm.Id = id;
            }
            MessageModel msg = ctrl.add(mm);

            if (msg.Code == 0)
            {
                parentForm.loadData();
                this.Close();
            }
            else
            {
                MessageBox.Show(msg.Msg);
            }
        }
Example #3
0
        public MessageModel add(object obj)
        {
            MaterielModel s   = (MaterielModel)obj;
            string        sql = "";

            if (s.Id > 0)
            {
                sql = "UPDATE materiel SET num = '" + s.Num + "',name = '" + s.Name + "',specifications = '" + s.Specifications + "',metering = '" + s.Metering + "',subMetering = @subMetering,conversion = @conversion,type = '" + s.Type + "',tax = '" + s.Tax + "',isBatch = @isBatch,category = @catgegory ";
                if (s.Type == "外购件" && s.NormPrice != null)
                {
                    sql += ",normprice = @normprice ";
                }
                sql += " WHERE id = '" + s.Id + "' ";
            }
            else
            {
                sql = "insert into materiel (num,name,specifications,metering,subMetering,conversion,type,tax,isBatch,category,normprice) values('"
                      + s.Num + "','" + s.Name + "','" + s.Specifications + "','" + s.Metering + "',@subMetering,@conversion,'" + s.Type + "','" + s.Tax + "',@isBatch, @catgegory,@normprice);";
            }
            MessageModel msg;

            try
            {
                Dictionary <string, object> paras = new Dictionary <string, object>();
                paras.Add("@isBatch", s.IsBatch);
                paras.Add("@subMetering", s.SubMetering);
                paras.Add("@conversion", s.Conversion);
                paras.Add("@catgegory", s.Catgegory);
                paras.Add("@normprice", s.NormPrice);
                int res = h.ExecuteNonQuery(sql, paras, CommandType.Text);
                if (res > 0)
                {
                    msg = new MessageModel(0, "保存成功", s);
                }
                else
                {
                    msg = new MessageModel(10005, "保存失败");
                }
            }
            catch (Exception e)
            {
                string err = "服务器错误,请重试!" + e.ToString();
                if (e.ToString().IndexOf("num_UNIQUE") != -1)
                {
                    err = "编码重复!";
                }
                msg = new MessageModel(10005, err);
            }
            return(msg);
        }
Example #4
0
        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                this.dataGridView1.CurrentCell = null;
                List <MaterielModel> list_m = new List <MaterielModel>();
                for (int i = this.dataGridView1.RowCount; i > 0; i--)
                {
                    MaterielModel model = new MaterielModel();
                    model.Id = Convert.ToInt32(this.dataGridView1.Rows[i - 1].Cells["id"].Value);
                    if (this.dataGridView1.Rows[i - 1].Cells["safetystock"].Value != DBNull.Value)
                    {
                        model.safetystock = Math.Round(Convert.ToDouble(this.dataGridView1.Rows[i - 1].Cells["safetystock"].Value), 2);
                    }
                    if (this.dataGridView1.Rows[i - 1].Cells["maxstock"].Value != DBNull.Value)
                    {
                        model.maxstock = Math.Round(Convert.ToDouble(this.dataGridView1.Rows[i - 1].Cells["maxstock"].Value), 2);
                    }
                    if (model.safetystock == null)
                    {
                        MessageBox.Show("物料缺失安全数量!");
                        return;
                    }

                    list_m.Add(model);
                }

                var msg = ctrl.addstock(list_m);
                if (msg.Code == 0)
                {
                    MessageBox.Show(msg.Msg);
                    this.Close();
                }
                else
                {
                    MessageBox.Show(msg.Msg);
                }
            }
            catch (Exception ext)
            {
                MessageBox.Show(ext.Message);
            }
        }
Example #5
0
 public ActionResult Save(MaterielModel mat)
 {
     try
     {
         if (mat.Id == 0)
         {
             mat.CreateUser = CurrentUser.Id;
         }
         else
         {
             mat.UpdateUser = CurrentUser.Id;
         }
         return(Json(new JsonMessage(business.Save(mat))));
     }
     catch (Exception e)
     {
         return(Json(new JsonMessage(false, e.Message)));
     }
 }