Exemplo n.º 1
0
 private void btnSave_Click(object sender, EventArgs e)
 {
     try
     {
         LightPercentModel obj = new LightPercentModel();
         obj.Id   = ObjId;
         obj.Name = cbLightPer.Text;
         obj.Type = (int)eLightType.BTPConLai;
         for (var i = 0; i < gridViewDe.RowCount; i++)
         {
             var row = gridViewDe.GetRow(gridViewDe.GetRowHandle(i));
             obj.Childs.Add((LightPercentDetailModel)row);
         }
         if (BLLLightPercent.Instance.InsertOrUpdate(obj).IsSuccess)
         {
             MessageBox.Show("Lưu thông tin thành công.");
             loadPhanCongTyLe();
             gridViewDe.OptionsBehavior.Editable = false;
             butClick(3);
         }
         else
         {
             MessageBox.Show("Lưu thông tin thất bại.");
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("Lỗi: " + ex.Message);
     }
 }
        private void btnSave_Click(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(cbtile.Text))
            {
                ResponseBase rs;
                var          obj = new LightPercentModel()
                {
                    Id   = Id,
                    Name = cbtile.Text,
                    Type = (int)eLightType.KanBan
                };
                var listReadPercent = new List <LightPercentDetailModel>();
                if (dgTyLe.Rows.Count > 0)
                {
                    LightPercentDetailModel rp;
                    for (int i = 0; i < dgTyLe.Rows.Count - 1; i++)
                    {
                        rp = new  LightPercentDetailModel();
                        DataGridViewRow row = dgTyLe.Rows[i];
                        if (row != null)
                        {
                            float percentFrom = 0;
                            if (row.Cells["dgPercentFrom"].Value != null)
                            {
                                float.TryParse(row.Cells["dgPercentFrom"].Value.ToString(), out percentFrom);
                            }
                            rp.From = percentFrom;

                            float percentTo = 0;
                            if (row.Cells["dgPercentTo"].Value != null)
                            {
                                float.TryParse(row.Cells["dgPercentTo"].Value.ToString(), out percentTo);
                            }
                            rp.To = percentTo;

                            string ColorName = string.Empty;
                            if (row.Cells["lightColor"].Value != null)
                            {
                                ColorName = row.Cells["lightColor"].Value.ToString();
                            }
                            rp.ColorName = ColorName;
                            listReadPercent.Add(rp);
                        }
                    }
                    obj.Childs.AddRange(listReadPercent);
                }
                if (Id == 0)
                {
                    rs = BLLLightPercent.Instance.InsertOrUpdate(obj);
                }
                else
                {
                    rs = BLLLightPercent.Instance.Update(Id, cbtile.Text, listReadPercent);
                }
                if (rs.IsSuccess)
                {
                    ProcessButton(4);
                    dgTyLe.Enabled = false;
                    loadPhanCongTyLe();
                    loadDSTyLe();
                    Id = 0;
                    MessageBox.Show("Lưu thông tin thành công");
                }
            }
            else
            {
                MessageBox.Show("Tên tỷ lệ không được để trống", "Lỗi thao tác", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Exemplo n.º 3
0
        public ResponseBase InsertOrUpdate(LightPercentModel model)
        {
            var result = new ResponseBase();

            try
            {
                using (var _db = new PMSEntities())
                {
                    P_LightPercent lightObj;
                    if (model.Id == 0)
                    {
                        lightObj = new P_LightPercent();
                        Parse.CopyObject(model, ref lightObj);
                        lightObj.IsDeleted = false;
                        if (model.Childs != null && model.Childs.Count > 0)
                        {
                            lightObj.P_LightPercent_De = new List <P_LightPercent_De>();
                            P_LightPercent_De subItem;
                            foreach (var itemObj in model.Childs)
                            {
                                subItem = new P_LightPercent_De();
                                Parse.CopyObject(itemObj, ref subItem);
                                subItem.IsDeleted      = false;
                                subItem.P_LightPercent = lightObj;
                                lightObj.P_LightPercent_De.Add(subItem);
                            }
                        }
                        _db.P_LightPercent.Add(lightObj);
                    }
                    else
                    {
                        lightObj = _db.P_LightPercent.FirstOrDefault(x => x.Id == model.Id);
                        if (lightObj != null)
                        {
                            lightObj.Name = model.Name;
                            lightObj.P_LightPercent_De.ToList().ForEach(x => _db.P_LightPercent_De.Remove(x));
                            lightObj.P_LightPercent_De = new List <P_LightPercent_De>();
                            if (model.Childs.Count > 0)
                            {
                                P_LightPercent_De subItem;
                                foreach (var itemObj in model.Childs)
                                {
                                    subItem = new P_LightPercent_De();
                                    Parse.CopyObject(itemObj, ref subItem);
                                    subItem.IsDeleted      = false;
                                    subItem.P_LightPercent = lightObj;
                                    lightObj.P_LightPercent_De.Add(subItem);
                                }
                            }
                        }
                    }
                    _db.SaveChanges();
                    result.IsSuccess = true;
                    result.Messages.Add(new Message()
                    {
                        Title = "Thông Báo", msg = "Lưu thành công."
                    });
                }
            }
            catch (Exception ex)
            { }
            return(result);
        }