コード例 #1
0
 private void Save()
 {
     if (string.IsNullOrEmpty(txtName.Text))
     {
         MessageBox.Show("Vui lòng nhập tên công đoạn.", "Lỗi nhập liệu", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
     else
     {
         var obj = new P_CompletionPhase();
         obj.Id          = PId;
         obj.OrderIndex  = (int)txtOrderIndex.Value;
         obj.Code        = txtCode.Text;
         obj.Name        = txtName.Text;
         obj.Note        = txtNote.Text;
         obj.IsShow      = cbShow.Checked;
         obj.CreatedDate = DateTime.Now;
         var rs = BLLCompletionPhase.InsertOrUpdate(obj);
         if (rs.IsSuccess)
         {
             //  MessageBox.Show(rs.Messages[0].msg, rs.Messages[0].Title, MessageBoxButtons.OK, MessageBoxIcon.None);
             LoadCompletionPhase();
             ResetForm();
         }
         else
         {
             MessageBox.Show(rs.Messages[0].msg, rs.Messages[0].Title, MessageBoxButtons.OK, MessageBoxIcon.Error);
         }
     }
 }
コード例 #2
0
        private void btnAdd_s_Click(object sender, EventArgs e)
        {
            AssignCompletionModel sp    = (AssignCompletionModel)cboSanPham_0.SelectedItem;
            P_CompletionPhase     phase = (P_CompletionPhase)cbPhase.SelectedItem;
            var obj = new P_CompletionPhase_Daily();

            obj.AssignId          = sp.Id;
            obj.CommandTypeId     = radioGroup1.SelectedIndex == 0 ? (int)eCommandRecive.ProductIncrease : (int)eCommandRecive.ProductReduce;
            obj.Date              = date;
            obj.CompletionPhaseId = phase.Id;
            obj.CreatedDate       = DateTime.Now;
            obj.Quantity          = (int)txtsl.Value;
            var rs = BLLInsertQuality.Insert(obj);

            if (rs.IsSuccess)
            {
                GetDataForGridView(sp);
                ResetForm();
            }
            else
            {
                MessageBox.Show(rs.Messages[0].msg, rs.Messages[0].Title, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
コード例 #3
0
        /// <summary>
        /// Insert or Update công đoạn hoàn thành
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public static ResponseBase InsertOrUpdate(P_CompletionPhase obj)
        {
            var rs = new ResponseBase();

            try
            {
                var db = new PMSEntities();
                P_CompletionPhase newObj;
                rs.IsSuccess = true;
                if (!string.IsNullOrEmpty(obj.Code))
                {
                    if (CheckExists(obj.Id, obj.Code, false, db) != null)
                    {
                        rs.IsSuccess = false;
                        rs.Messages.Add(new Message()
                        {
                            msg = "Mã công đoạn đã tồn vui lòng chọn mã khác.", Title = "Lỗi trùng dữ liệu"
                        });
                    }
                }
                if (rs.IsSuccess)
                {
                    if (CheckExists(obj.Id, obj.Name, true, db) != null)
                    {
                        rs.IsSuccess = false;
                        rs.Messages.Add(new Message()
                        {
                            msg = "Tên công đoạn đã tồn vui lòng chọn mã khác.", Title = "Lỗi trùng dữ liệu"
                        });
                    }
                    else
                    {
                        if (obj.Id == 0)
                        {
                            newObj = new P_CompletionPhase();
                            Parse.CopyObject(obj, ref newObj);
                            db.P_CompletionPhase.Add(newObj);
                            rs.IsSuccess = true;
                        }
                        else
                        {
                            newObj = db.P_CompletionPhase.FirstOrDefault(x => x.Id == obj.Id);
                            if (newObj != null)
                            {
                                newObj.OrderIndex = obj.OrderIndex;
                                newObj.Code       = obj.Code;
                                newObj.Name       = obj.Name;
                                newObj.Note       = obj.Note;
                                newObj.IsShow     = obj.IsShow;
                                rs.IsSuccess      = true;
                            }
                            else
                            {
                                rs.IsSuccess = false;
                                rs.Messages.Add(new Message()
                                {
                                    Title = "Lỗi", msg = "Không tìm thấy thông tin. cập nhật thất bại"
                                });
                            }
                        }
                        if (rs.IsSuccess)
                        {
                            db.SaveChanges();
                            rs.IsSuccess = true;
                            rs.Messages.Add(new Message()
                            {
                                Title = "Thông báo", msg = "Lưu thành công."
                            });
                        }
                    }
                }
            }
            catch (Exception)
            {
                rs.IsSuccess = false;
                rs.Messages.Add(new Message()
                {
                    Title = "Lỗi", msg = "Không tìm thấy thông tin. cập nhật thất bại"
                });
            }
            return(rs);
        }