예제 #1
0
 private void DelBtn_Click(object sender, EventArgs e)
 {
     try
     {
         var selectedRows = ViTriGrid.Rows.GetRowCount(DataGridViewElementStates.Selected);
         if (selectedRows == 0)
         {
             MessageBox.Show("Vui lòng chọn tối thiểu một đơn giá để xóa", "Thao tác", MessageBoxButtons.OK, MessageBoxIcon.Warning);
         }
         else
         {
             var result = MessageBox.Show("Bạn có chắc chắn xóa?", "Xóa", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
             if (result == DialogResult.Yes)
             {
                 Cursor.Current = Cursors.WaitCursor;
                 var db = new CkpEntities();
                 for (int i = 0; i < selectedRows; i++)
                 {
                     var id = ViTriGrid.SelectedRows[i].Cells[0].Value.ToString();
                     var dg = (from d in db.ViTriBom where d.ViTri == id select d).FirstOrDefault();
                     dg.TrangThai = 0;
                     db.SaveChanges();
                 }
                 Cursor.Current = Cursors.Default;
                 MessageBox.Show("Đã xóa " + selectedRows + " vị trí", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                 UpdateDataGrid();
             }
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.GetBaseException().Message, "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
예제 #2
0
        private void OkBtn_Click(object sender, EventArgs e)
        {
            var name = HtTBox.Text.Trim();
            var cvu  = CvTBox.Text.Trim();
            var sdt  = SdtTBox.Text.Trim();
            var dc   = DcTBox.Text.Trim();

            if (name.Length == 0 || cvu.Length == 0)
            {
                if (name.Length == 0)
                {
                    HtLbl.ForeColor = Color.Red;
                }
                else
                {
                    HtLbl.ForeColor = Color.Black;
                }

                if (cvu.Length == 0)
                {
                    CvLbl.ForeColor = Color.Red;
                }
                else
                {
                    CvLbl.ForeColor = Color.Black;
                }
            }
            else
            {
                try
                {
                    Cursor.Current = Cursors.WaitCursor;
                    var db    = new CkpEntities();
                    var newNv = new NhanVien
                    {
                        HoTen       = name,
                        ChucVu      = cvu,
                        SoDienThoai = sdt.Length == 0 ? null : sdt,
                        DiaChi      = dc.Length == 0 ? null : dc,
                        TrangThai   = 1,
                        NgayTao     = DateTime.Now,
                        NgaySuaCuoi = DateTime.Now
                    };
                    db.NhanVien.Add(newNv);
                    db.SaveChanges();

                    Cursor.Current = Cursors.Default;
                    parentForm.UpdateDataGrid();
                    MessageBox.Show("Thêm nhân viên thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                    Close();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.GetBaseException().Message, "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
예제 #3
0
        private void OkBtn_Click(object sender, EventArgs e)
        {
            var name = HtTBox.Text.Trim();
            var cvu  = CvTBox.Text.Trim();
            var sdt  = SdtTBox.Text.Trim();
            var dc   = DcTBox.Text.Trim();

            if (name.Length == 0 || cvu.Length == 0)
            {
                if (name.Length == 0)
                {
                    HtLbl.ForeColor = Color.Red;
                }
                else
                {
                    HtLbl.ForeColor = Color.Black;
                }

                if (cvu.Length == 0)
                {
                    CvLbl.ForeColor = Color.Red;
                }
                else
                {
                    CvLbl.ForeColor = Color.Black;
                }
            }
            else
            {
                try
                {
                    Cursor.Current = Cursors.WaitCursor;
                    var db = new CkpEntities();
                    var nv = (from n in db.NhanVien where n.Id == NvId select n).First();

                    nv.HoTen       = name;
                    nv.ChucVu      = cvu;
                    nv.SoDienThoai = sdt.Length == 0 ? null : sdt;
                    nv.DiaChi      = dc.Length == 0 ? null : dc;
                    nv.NgaySuaCuoi = DateTime.Now;

                    db.SaveChanges();

                    Cursor.Current = Cursors.Default;
                    parentForm.UpdateDataGrid();
                    MessageBox.Show("Thay đổi thông tin nhân viên thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                    Close();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.GetBaseException().Message, "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
예제 #4
0
        private void OkBtn_Click(object sender, EventArgs e)
        {
            var viTri = ViTriTBox.Text.Trim();

            if (viTri.Length == 0)
            {
                if (viTri.Length == 0)
                {
                    ViTriLbl.ForeColor = Color.Red;
                }
                else
                {
                    ViTriLbl.ForeColor = Color.Black;
                }
            }
            else
            {
                try
                {
                    Cursor.Current = Cursors.WaitCursor;
                    var db = new CkpEntities();

                    if (db.ViTriBom.Select(v => v.ViTri).Contains(viTri))
                    {
                        MessageBox.Show("Vị trí bơm này đã tồn tại", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }

                    var newVt = new ViTriBom
                    {
                        ViTri       = viTri,
                        TrangThai   = 1,
                        NgayTao     = DateTime.Now,
                        NgaySuaCuoi = DateTime.Now
                    };
                    db.ViTriBom.Add(newVt);
                    db.SaveChanges();

                    Cursor.Current = Cursors.Default;
                    parentForm.UpdateDataGrid();
                    MessageBox.Show("Thêm vị trí thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                    Close();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.GetBaseException().Message, "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
예제 #5
0
        private void EditBtn_Click(object sender, EventArgs e)
        {
            try
            {
                var db   = new CkpEntities();
                var name = NameTBox.Text;
                var id   = IdTbox.Text;
                if (name.Length > 0)
                {
                    Cursor.Current = Cursors.WaitCursor;

                    var mayBom = (from b in db.MayBom where b.Id == id select b).FirstOrDefault();
                    mayBom.TenBom      = name.Trim();
                    mayBom.LoaiBom     = TypeCBox.SelectedIndex == 0 ? 1 : 2;
                    mayBom.NgaySuaCuoi = DateTime.Now;
                    db.SaveChanges();

                    Cursor.Current = Cursors.Default;
                    MessageBox.Show("Sửa thông tin thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    parentForm.UpdateDataGrid();
                    Close();
                }
                else
                {
                    if (id.Length == 0)
                    {
                        IdLbl.ForeColor = Color.Red;
                    }
                    else
                    {
                        IdLbl.ForeColor = Color.Black;
                    }

                    if (id.Length == 0)
                    {
                        NameLbl.ForeColor = Color.Red;
                    }
                    else
                    {
                        NameLbl.ForeColor = Color.Black;
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.GetBaseException().Message, "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
예제 #6
0
파일: SuaViTri.cs 프로젝트: thinh-nd/CkpApp
        private void OkBtn_Click(object sender, EventArgs e)
        {
            var viTri = ViTriTBox.Text.Trim();

            if (viTri.Length == 0)
            {
                if (viTri.Length == 0)
                {
                    ViTriLbl.ForeColor = Color.Red;
                }
                else
                {
                    ViTriLbl.ForeColor = Color.Black;
                }
            }
            else
            {
                try
                {
                    Cursor.Current = Cursors.WaitCursor;
                    var db = new CkpEntities();

                    var allVt = (from d in db.ViTriBom where d.ViTri == Vt select d);

                    if (allVt.Select(v => v.ViTri).Contains(viTri))
                    {
                        MessageBox.Show("Vị trí bơm này đã tồn tại", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
                    var vt = allVt.FirstOrDefault();

                    vt.ViTri       = viTri;
                    vt.NgaySuaCuoi = DateTime.Now;

                    db.SaveChanges();

                    Cursor.Current = Cursors.Default;
                    parentForm.UpdateDataGrid();
                    MessageBox.Show("Thay đổi vị trí thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                    Close();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.GetBaseException().Message, "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
예제 #7
0
        private void DelBtn_Click(object sender, EventArgs e)
        {
            try
            {
                var selectedRows = CTrGrid.Rows.GetRowCount(DataGridViewElementStates.Selected);

                if (selectedRows == 0)
                {
                    MessageBox.Show("Vui lòng chọn ít nhât một công trình để xóa", "Thao tác", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
                else
                {
                    var result = MessageBox.Show("Bạn có chắc chắn xóa?", "Xóa", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
                    if (result == DialogResult.Yes)
                    {
                        Cursor.Current = Cursors.WaitCursor;
                        var db = new CkpEntities();
                        for (int i = 0; i < selectedRows; i++)
                        {
                            var id  = CTrGrid.SelectedRows[i].Cells[0].Value.ToString();
                            var ctr = (from c in db.CongTrinh where c.Id == id && c.TrangThai == 1 select c).FirstOrDefault();
                            ctr.TrangThai   = 0;
                            ctr.NgaySuaCuoi = DateTime.Now;
                            db.SaveChanges();
                        }
                        Cursor.Current = Cursors.Default;
                        MessageBox.Show("Đã xóa " + selectedRows + " công trình", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                        UpdateDataGrid();
                    }
                }
            }
            catch (Exception ex)
            {
                Cursor.Current = Cursors.Default;
                MessageBox.Show(ex.GetBaseException().Message, "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
예제 #8
0
 private void DelBtn_Click(object sender, EventArgs e)
 {
     try
     {
         var selectedRows = BaoCaoGrid.Rows.GetRowCount(DataGridViewElementStates.Selected);
         if (selectedRows == 0)
         {
             MessageBox.Show("Vui lòng chọn tối thiểu một báo cáo để xóa", "Thao tác", MessageBoxButtons.OK, MessageBoxIcon.Warning);
         }
         else
         {
             var result = MessageBox.Show("Bạn có chắc chắn xóa?", "Xóa", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
             if (result == DialogResult.Yes)
             {
                 Cursor.Current = Cursors.WaitCursor;
                 var db = new CkpEntities();
                 for (int i = 0; i < selectedRows; i++)
                 {
                     var id = int.Parse(BaoCaoGrid.SelectedRows[i].Cells[0].Value.ToString());
                     var bc = (from b in db.BaoCaoNgay where b.Id == id select b).FirstOrDefault();
                     bc.TrangThai   = 0;
                     bc.NgaySuaCuoi = DateTime.Now;
                     db.SaveChanges();
                 }
                 Cursor.Current = Cursors.Default;
                 MessageBox.Show("Đã xóa " + selectedRows + " báo cáo", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                 UpdateSearchResult();
             }
         }
     }
     catch (Exception ex)
     {
         Cursor.Current = Cursors.Default;
         MessageBox.Show(ex.GetBaseException().Message, "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
예제 #9
0
        private void AddBtn_Click(object sender, EventArgs e)
        {
            try
            {
                DateTime ngayKy = new DateTime();
                DateTime ngayTh = new DateTime();
                var      cul    = CultureInfo.InvariantCulture;
                var      dts    = DateTimeStyles.None;

                if ((!DateTime.TryParseExact(NgayKyTBox.Text, "ddMMyyyy", cul, dts, out ngayKy) && NgayKyTBox.Text.Length > 0) ||
                    (!DateTime.TryParseExact(NgayThTBox.Text, "ddMMyyyy", cul, dts, out ngayTh) && NgayThTBox.Text.Length > 0))
                {
                    MessageBox.Show("Ngày ký hoặc ngày thực hiện không đúng format ddMMyyyy", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                var id   = CtrIdTBox.Text.Trim();
                var name = CtrNameTBox.Text.Trim();
                if (id.Length == 0 || name.Length == 0)
                {
                    if (id.Length == 0)
                    {
                        CtrIdTBox.ForeColor = Color.Red;
                    }
                    else
                    {
                        CtrIdTBox.ForeColor = Color.Black;
                    }

                    if (name.Length == 0)
                    {
                        CtrNameTBox.ForeColor = Color.Red;
                    }
                    else
                    {
                        CtrNameTBox.ForeColor = Color.Black;
                    }
                }
                else
                {
                    Cursor.Current = Cursors.WaitCursor;
                    var db  = new CkpEntities();
                    var ctr = (from c in db.CongTrinh where c.Id == id select c).First();
                    ctr.TenCongTrinh    = name;
                    ctr.DiaChi          = CtrDcTBox.Text.Length > 0 ? CtrDcTBox.Text.Trim() : null;
                    ctr.SoHopDong       = SoHdTBox.Text.Length > 0 ? SoHdTBox.Text.Trim() : null;
                    ctr.NguoiPhuTrachId = NptCb.SelectedIndex > -1 ? int.Parse(NptCb.Text.Split('.')[0]) : (int?)null;
                    ctr.NgayKyHD        = NgayKyTBox.Text.Length > 0 ? ngayKy : (DateTime?)null;
                    ctr.NgayThucHien    = NgayThTBox.Text.Length > 0 ? ngayTh : (DateTime?)null;
                    ctr.NgaySuaCuoi     = DateTime.Now;

                    db.SaveChanges();

                    Cursor.Current = Cursors.Default;
                    MessageBox.Show("Cập nhật thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                    parentForm.UpdateDataGrid();
                    Close();
                }
            }
            catch (Exception ex)
            {
                var exMsg = ex.GetBaseException().Message;
                if (exMsg.Contains("Violation of PRIMARY KEY constrain"))
                {
                    MessageBox.Show("Mã công trình đã tồn tại", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                else
                {
                    MessageBox.Show(ex.GetBaseException().Message, "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
예제 #10
0
        private void OkBtn_Click(object sender, EventArgs e)
        {
            var KhId = KhIdTBox.Text.Trim();
            var Cty  = CtyTBox.Text.Trim();
            var Mst  = MstTBox.Text.Trim();
            var Dc   = DcTBox.Text.Trim();

            var db = new CkpEntities();

            if (KhId.Length == 0 || Cty.Length == 0)
            {
                if (KhId.Length == 0)
                {
                    KhIdLbl.ForeColor = Color.Red;
                }
                else
                {
                    KhIdLbl.ForeColor = Color.Black;
                }

                if (Cty.Length == 0)
                {
                    CtyLbl.ForeColor = Color.Red;
                }
                else
                {
                    CtyLbl.ForeColor = Color.Black;
                }
            }
            else
            {
                try
                {
                    Cursor.Current = Cursors.WaitCursor;
                    var kh = (from k in db.KhachHang where k.Id == KhachHangId select k).First();
                    kh.Id          = KhId;
                    kh.TenCongTy   = Cty;
                    kh.MaSoThue    = Mst;
                    kh.DiaChi      = Dc.Length == 0 ? null : Dc;
                    kh.NgaySuaCuoi = DateTime.Now;

                    if (Nlh1TBox.Text.Length > 0)
                    {
                        var nlh  = (from n in kh.NguoiLienHe where n.Id == NlhIds[0] select n).FirstOrDefault();
                        var Nlh1 = Nlh1TBox.Text.Trim();
                        var Cvu1 = Cvu1TBox.Text.Trim();
                        var Sdt1 = Sdt1TBox.Text.Trim();
                        var Gc1  = Gc1TBox.Text.Trim();

                        if (nlh != null)
                        {
                            nlh.HoTen       = Nlh1;
                            nlh.Chucvu      = Cvu1.Length == 0 ? null : Cvu1;
                            nlh.SoDienThoai = Sdt1.Length == 0 ? null : Sdt1;
                            nlh.GhiChu      = Gc1.Length == 0 ? null : Gc1;
                        }
                        else
                        {
                            var newNlh = new NguoiLienHe
                            {
                                HoTen       = Nlh1,
                                Chucvu      = Cvu1,
                                SoDienThoai = Sdt1,
                                GhiChu      = Gc1,
                                KhachHangId = KhId,
                                TrangThai   = 1,
                                NgayTao     = DateTime.Now,
                                NgaySuaCuoi = DateTime.Now,
                            };
                            db.NguoiLienHe.Add(newNlh);
                        }
                    }
                    else
                    {
                        if (NlhIds[0] != 0)
                        {
                            var nlh = (from n in kh.NguoiLienHe where n.Id == NlhIds[0] select n).FirstOrDefault();
                            nlh.TrangThai = 0;
                        }
                    }

                    if (Nlh2TBox.Text.Length > 0)
                    {
                        var nlh  = (from n in kh.NguoiLienHe where n.Id == NlhIds[1] select n).FirstOrDefault();
                        var Nlh2 = Nlh2TBox.Text.Trim();
                        var Cvu2 = Cvu2TBox.Text.Trim();
                        var Sdt2 = Sdt2TBox.Text.Trim();
                        var Gc2  = Gc2TBox.Text.Trim();

                        if (nlh != null)
                        {
                            nlh.HoTen       = Nlh2;
                            nlh.Chucvu      = Cvu2.Length == 0 ? null : Cvu2;
                            nlh.SoDienThoai = Sdt2.Length == 0 ? null : Sdt2;
                            nlh.GhiChu      = Gc2.Length == 0 ? null : Gc2;
                        }
                        else
                        {
                            var newNlh = new NguoiLienHe
                            {
                                HoTen       = Nlh2,
                                Chucvu      = Cvu2,
                                SoDienThoai = Sdt2,
                                GhiChu      = Gc2,
                                KhachHangId = KhId,
                                TrangThai   = 1,
                                NgayTao     = DateTime.Now,
                                NgaySuaCuoi = DateTime.Now,
                            };
                            db.NguoiLienHe.Add(newNlh);
                        }
                    }
                    else
                    {
                        if (NlhIds[1] != 0)
                        {
                            var nlh = (from n in kh.NguoiLienHe where n.Id == NlhIds[1] select n).FirstOrDefault();
                            nlh.TrangThai = 0;
                        }
                    }

                    if (Nlh3TBox.Text.Length > 0)
                    {
                        var nlh  = (from n in kh.NguoiLienHe where n.Id == NlhIds[2] select n).FirstOrDefault();
                        var Nlh3 = Nlh3TBox.Text.Trim();
                        var Cvu3 = Cvu3TBox.Text.Trim();
                        var Sdt3 = Sdt3TBox.Text.Trim();
                        var Gc3  = Gc3TBox.Text.Trim();

                        if (nlh != null)
                        {
                            nlh.HoTen       = Nlh3;
                            nlh.Chucvu      = Cvu3.Length == 0 ? null : Cvu3;
                            nlh.SoDienThoai = Sdt3.Length == 0 ? null : Sdt3;
                            nlh.GhiChu      = Gc3.Length == 0 ? null : Gc3;
                        }
                        else
                        {
                            var newNlh = new NguoiLienHe
                            {
                                HoTen       = Nlh3,
                                Chucvu      = Cvu3,
                                SoDienThoai = Sdt3,
                                GhiChu      = Gc3,
                                KhachHangId = KhId,
                                TrangThai   = 1,
                                NgayTao     = DateTime.Now,
                                NgaySuaCuoi = DateTime.Now,
                            };
                            db.NguoiLienHe.Add(newNlh);
                        }
                    }
                    else
                    {
                        if (NlhIds[2] != 0)
                        {
                            var nlh = (from n in kh.NguoiLienHe where n.Id == NlhIds[2] select n).FirstOrDefault();
                            nlh.TrangThai = 0;
                        }
                    }

                    if (Nlh4TBox.Text.Length > 0)
                    {
                        var nlh  = (from n in kh.NguoiLienHe where n.Id == NlhIds[3] select n).FirstOrDefault();
                        var Nlh4 = Nlh4TBox.Text.Trim();
                        var Cvu4 = Cvu4TBox.Text.Trim();
                        var Sdt4 = Sdt4TBox.Text.Trim();
                        var Gc4  = Gc4TBox.Text.Trim();

                        if (nlh != null)
                        {
                            nlh.HoTen       = Nlh4;
                            nlh.Chucvu      = Cvu4.Length == 0 ? null : Cvu4;
                            nlh.SoDienThoai = Sdt4.Length == 0 ? null : Sdt4;
                            nlh.GhiChu      = Gc4.Length == 0 ? null : Gc4;
                        }
                        else
                        {
                            var newNlh = new NguoiLienHe
                            {
                                HoTen       = Nlh4,
                                Chucvu      = Cvu4,
                                SoDienThoai = Sdt4,
                                GhiChu      = Gc4,
                                KhachHangId = KhId,
                                TrangThai   = 1,
                                NgayTao     = DateTime.Now,
                                NgaySuaCuoi = DateTime.Now,
                            };
                            db.NguoiLienHe.Add(newNlh);
                        }
                    }
                    else
                    {
                        if (NlhIds[3] != 0)
                        {
                            var nlh = (from n in kh.NguoiLienHe where n.Id == NlhIds[3] select n).FirstOrDefault();
                            nlh.TrangThai = 0;
                        }
                    }

                    db.SaveChanges();

                    parentForm.UpdateDataGrid();
                    Cursor.Current = Cursors.Default;
                    MessageBox.Show("Cập nhật khách hàng thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                    Close();
                }
                catch (Exception ex)
                {
                    var exMsg = ex.GetBaseException().Message;
                    if (exMsg.Contains("Violation of PRIMARY KEY constrain"))
                    {
                        MessageBox.Show("Mã khách hàng đã tồn tại", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    else
                    {
                        MessageBox.Show(exMsg, "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
            }
        }
예제 #11
0
        private void OkBtn_Click(object sender, EventArgs e)
        {
            try
            {
                Cursor.Current = Cursors.WaitCursor;
                var db = new CkpEntities();
                if (TenDgTBox.Text.Length == 0)
                {
                    TenDgLbl.ForeColor = Color.Red;
                    return;
                }
                else
                {
                    TenDgLbl.ForeColor = Color.Black;
                }

                foreach (TextBox tb in this.Controls.OfType <TextBox>())
                {
                    int val = 0;
                    if (tb.Name == "TenDgTBox" || tb.Name == "CthucTBox" || tb.Name == "CtrTBox")
                    {
                        continue;
                    }
                    else
                    {
                        if (tb.Text.Length > 0 && !int.TryParse(tb.Text.Replace(",", ""), out val))
                        {
                            MessageBox.Show("Tất cả các thông tin số liệu phải là số", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            return;
                        }
                    }
                }

                var dg = (from d in db.DonGiaBom where d.Id == DgId select d).FirstOrDefault();

                dg.TenDonGia       = TenDgTBox.Text;
                dg.DonGia          = Dg0TBox.Text.Length > 0 ? int.Parse(Dg0TBox.Text.Replace(",", "")) : (int?)null;
                dg.DonGiaVAT       = Dg1TBox.Text.Length > 0 ? int.Parse(Dg1TBox.Text.Replace(",", "")) : (int?)null;
                dg.VAT             = VatTBox.Text.Length > 0 ? int.Parse(VatTBox.Text) : (int?)null;
                dg.MinKlgBomCan    = MinBcTBox.Text.Length > 0 ? int.Parse(MinBcTBox.Text) : (int?)null;
                dg.MinKlgBomTinh   = MinBtTBox.Text.Length > 0 ? int.Parse(MinBtTBox.Text) : (int?)null;
                dg.CC1             = Cc1TBox.Text.Length > 0 ? int.Parse(Cc1TBox.Text.Replace(",", "")) : (int?)null;
                dg.TongCC2         = TgCc2TBox.Text.Length > 0 ? int.Parse(TgCc2TBox.Text.Replace(",", "")) : (int?)null;
                dg.PhanTramBackCC2 = PtCc2TBox.Text.Length > 0 ? int.Parse(PtCc2TBox.Text) : (int?)null;
                dg.TienBackCC2     = BackCc2TBox.Text.Length > 0 ? int.Parse(BackCc2TBox.Text.Replace(",", "")) : (int?)null;
                dg.NetCC2          = NetCc2TBox.Text.Length > 0 ? int.Parse(NetCc2TBox.Text.Replace(",", "")) : (int?)null;
                dg.TongThuVAT      = Kl1TBox.Text.Length > 0 ? int.Parse(Kl1TBox.Text.Replace(",", "")) : (int?)null;
                dg.TongVAT         = KlVatTBox.Text.Length > 0 ? int.Parse(KlVatTBox.Text.Replace(",", "")) : (int?)null;
                dg.TongThu         = Kl0TBox.Text.Length > 0 ? int.Parse(Kl0TBox.Text.Replace(",", "")) : (int?)null;
                dg.TongCC          = KlCcTBox.Text.Length > 0 ? int.Parse(KlCcTBox.Text.Replace(",", "")) : (int?)null;
                dg.CongThuc        = CthucTBox.Text;
                dg.GhiChu          = GcRtb.Text;
                dg.NgaySuaCuoi     = DateTime.Now;

                db.SaveChanges();

                Cursor.Current = Cursors.Default;
                MessageBox.Show("Thay đổi đơn giá thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                parentForm.UpdateDataGrid();
                Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.GetBaseException().Message, "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
예제 #12
0
        private void OkBtn_Click(object sender, EventArgs e)
        {
            var KhId = KhIdTBox.Text.Trim();
            var Cty  = CtyTBox.Text.Trim();
            var Mst  = MstTBox.Text.Trim();

            if (KhId.Length == 0 || Cty.Length == 0)
            {
                if (KhId.Length == 0)
                {
                    KhIdLbl.ForeColor = Color.Red;
                }
                else
                {
                    KhIdLbl.ForeColor = Color.Black;
                }

                if (Cty.Length == 0)
                {
                    CtyLbl.ForeColor = Color.Red;
                }
                else
                {
                    CtyLbl.ForeColor = Color.Black;
                }
            }
            else
            {
                try
                {
                    Cursor.Current = Cursors.WaitCursor;
                    var db    = new CkpEntities();
                    var newKh = new KhachHang
                    {
                        Id          = KhId,
                        TenCongTy   = Cty,
                        MaSoThue    = Mst,
                        DiaChi      = DcTBox.Text.Length == 0 ? null : DcTBox.Text.Trim(),
                        TrangThai   = 1,
                        NgayTao     = DateTime.Now,
                        NgaySuaCuoi = DateTime.Now
                    };

                    db.KhachHang.Add(newKh);
                    db.SaveChanges();

                    if (Nlh1TBox.Text.Length > 0)
                    {
                        var newNlh = new NguoiLienHe
                        {
                            HoTen       = Nlh1TBox.Text.Trim(),
                            Chucvu      = Cvu1TBox.Text.Length == 0 ? null : Cvu1TBox.Text.Trim(),
                            SoDienThoai = Sdt1TBox.Text.Length == 0 ? null : Sdt1TBox.Text.Trim(),
                            GhiChu      = Gc1TBox.Text.Length == 0 ? null : Gc1TBox.Text.Trim(),
                            KhachHangId = KhId,
                            TrangThai   = 1,
                            NgayTao     = DateTime.Now,
                            NgaySuaCuoi = DateTime.Now,
                        };

                        db.NguoiLienHe.Add(newNlh);
                        db.SaveChanges();
                    }

                    if (Nlh2TBox.Text.Length > 0)
                    {
                        var newNlh = new NguoiLienHe
                        {
                            HoTen       = Nlh2TBox.Text.Trim(),
                            Chucvu      = Cvu2TBox.Text.Length == 0 ? null : Cvu2TBox.Text.Trim(),
                            SoDienThoai = Sdt2TBox.Text.Length == 0 ? null : Sdt2TBox.Text.Trim(),
                            GhiChu      = Gc2TBox.Text.Length == 0 ? null : Gc2TBox.Text.Trim(),
                            KhachHangId = KhId,
                            TrangThai   = 1,
                            NgayTao     = DateTime.Now,
                            NgaySuaCuoi = DateTime.Now,
                        };

                        db.NguoiLienHe.Add(newNlh);
                        db.SaveChanges();
                    }

                    if (Nlh3TBox.Text.Length > 0)
                    {
                        var newNlh = new NguoiLienHe
                        {
                            HoTen       = Nlh3TBox.Text.Trim(),
                            Chucvu      = Cvu3TBox.Text.Length == 0 ? null : Cvu3TBox.Text.Trim(),
                            SoDienThoai = Sdt3TBox.Text.Length == 0 ? null : Sdt3TBox.Text.Trim(),
                            GhiChu      = Gc3TBox.Text.Length == 0 ? null : Gc3TBox.Text.Trim(),
                            KhachHangId = KhId,
                            TrangThai   = 1,
                            NgayTao     = DateTime.Now,
                            NgaySuaCuoi = DateTime.Now,
                        };

                        db.NguoiLienHe.Add(newNlh);
                        db.SaveChanges();
                    }

                    if (Nlh4TBox.Text.Length > 0)
                    {
                        var newNlh = new NguoiLienHe
                        {
                            HoTen       = Nlh4TBox.Text.Trim(),
                            Chucvu      = Cvu4TBox.Text.Length == 0 ? null : Cvu4TBox.Text.Trim(),
                            SoDienThoai = Sdt4TBox.Text.Length == 0 ? null : Sdt4TBox.Text.Trim(),
                            GhiChu      = Gc4TBox.Text.Length == 0 ? null : Gc4TBox.Text.Trim(),
                            KhachHangId = KhId,
                            TrangThai   = 1,
                            NgayTao     = DateTime.Now,
                            NgaySuaCuoi = DateTime.Now,
                        };

                        db.NguoiLienHe.Add(newNlh);
                        db.SaveChanges();
                    }

                    parentForm.UpdateDataGrid();
                    Cursor.Current = Cursors.Default;
                    MessageBox.Show("Tạo khách hàng mới thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                    Close();
                }
                catch (Exception ex)
                {
                    var exMsg = ex.GetBaseException().Message;
                    if (exMsg.Contains("Violation of PRIMARY KEY constrain"))
                    {
                        MessageBox.Show("Mã khách hàng đã tồn tại", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    else
                    {
                        MessageBox.Show(ex.GetBaseException().Message, "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
            }
        }
예제 #13
0
        private void OkBtn_Click(object sender, EventArgs e)
        {
            try
            {
                double   ftemp = 0;
                int      temp  = 0;
                DateTime dt    = DateTime.Now;

                if ((!int.TryParse(TangTb1.Text, out temp) && TangTb1.Text.Length > 0) ||
                    (!int.TryParse(TangTb2.Text, out temp) && TangTb2.Text.Length > 0) ||
                    (!int.TryParse(TangTb3.Text, out temp) && TangTb3.Text.Length > 0))
                {
                    MessageBox.Show("Tầng phải là số", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                if ((!double.TryParse(SlTb1.Text, out ftemp) && SlTb1.Text.Length > 0) ||
                    (!double.TryParse(SlTb2.Text, out ftemp) && SlTb2.Text.Length > 0) ||
                    (!double.TryParse(SlTb3.Text, out ftemp) && SlTb3.Text.Length > 0))
                {
                    MessageBox.Show("Số khối/số ca phải là số", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                if ((!double.TryParse(DgTtTb1.Text.Replace(",", ""), out ftemp) && DgTtTb1.Text.Length > 0) ||
                    (!double.TryParse(DgTtTb2.Text.Replace(",", ""), out ftemp) && DgTtTb2.Text.Length > 0) ||
                    (!double.TryParse(DgTtTb3.Text.Replace(",", ""), out ftemp) && DgTtTb3.Text.Length > 0))
                {
                    MessageBox.Show("Đơn giá trước thuế phải là số", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                if ((!double.TryParse(DgStTb1.Text.Replace(",", ""), out ftemp) && DgStTb1.Text.Length > 0) ||
                    (!double.TryParse(DgStTb2.Text.Replace(",", ""), out ftemp) && DgStTb2.Text.Length > 0) ||
                    (!double.TryParse(DgStTb3.Text.Replace(",", ""), out ftemp) && DgStTb3.Text.Length > 0))
                {
                    MessageBox.Show("Đơn giá sau thuế phải là số", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                if (!DateTime.TryParseExact(NgayBcTb.Text, "ddMMyyyy", CultureInfo.InvariantCulture, DateTimeStyles.None, out dt))
                {
                    MessageBox.Show("Ngày báo cáo không đúng format ddMMyyyy", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                foreach (DataGridViewRow row in NhanLucGrid.Rows)
                {
                    if (row.Cells[1].Value != null && !double.TryParse(row.Cells[1].Value.ToString(), out ftemp))
                    {
                        MessageBox.Show("Số khối bơm phải là số", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
                    if (row.Cells[2].Value != null && !int.TryParse(row.Cells[2].Value.ToString(), out temp))
                    {
                        MessageBox.Show("Lương/khối phải là số", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
                }

                if (BcId != 0) // if this is edit mode
                {
                    UpdateData();
                    return;
                }

                if (NgayBcTb.Text.Length == 0 || BomCb.SelectedIndex == -1 || NgBcCb.SelectedIndex == -1 || CtrCb.SelectedIndex == -1)
                {
                    if (NgayBcTb.Text.Length == 0)
                    {
                        NgayBcLbl.ForeColor = Color.Red;
                    }
                    else
                    {
                        NgayBcLbl.ForeColor = Color.Black;
                    }

                    if (BomCb.SelectedIndex == -1)
                    {
                        BomLbl.ForeColor = Color.Red;
                    }
                    else
                    {
                        BomLbl.ForeColor = Color.Black;
                    }

                    if (NgBcCb.SelectedIndex == -1)
                    {
                        NgBcLbl.ForeColor = Color.Red;
                    }
                    else
                    {
                        NgBcLbl.ForeColor = Color.Black;
                    }

                    if (CtrCb.SelectedIndex == -1)
                    {
                        CtrLbl.ForeColor = Color.Red;
                    }
                    else
                    {
                        CtrLbl.ForeColor = Color.Black;
                    }
                }
                else
                {
                    Cursor.Current = Cursors.WaitCursor;
                    var db  = new CkpEntities();
                    var cul = CultureInfo.InvariantCulture;

                    //Bao cao
                    var newReport = new BaoCaoNgay
                    {
                        NgayBaoCao    = DateTime.ParseExact(NgayBcTb.Text, "ddMMyyyy", cul),
                        NguoiBaoCaoId = NvIds[NgBcCb.SelectedIndex],
                        MayBomId      = BomIds[BomCb.SelectedIndex],
                        CongTrinhId   = CtrIds[CtrCb.SelectedIndex],
                        KhachHangId   = KhIds[KhCb.SelectedIndex],
                        TrangThai     = 1,
                        GhiChu        = GcRtb.Text,
                        NgayTao       = DateTime.Now,
                        NgaySuaCuoi   = DateTime.Now
                    };
                    db.BaoCaoNgay.Add(newReport);

                    //Vi tri
                    if (VtCb1.SelectedIndex > -1)
                    {
                        double dgv = 0;
                        double.TryParse(DgStTb1.Text.Replace(",", ""), out dgv);
                        double dg = 0;
                        double.TryParse(DgTtTb1.Text.Replace(",", ""), out dg);

                        var newVt = new ViTriBom_BaoCao
                        {
                            BaoCaoId  = newReport.Id,
                            ViTriId   = VtIds[VtCb1.SelectedIndex],
                            Tang      = TangTb1.Text.Length > 0 ? int.Parse(TangTb1.Text) : (int?)null,
                            SoLuong   = SlTb1.Text.Length > 0 ? double.Parse(SlTb1.Text) : (double?)null,
                            DonVi     = DvCb1.Text,
                            DonGiaVat = dgv,
                            DonGia    = dg,
                            GhiChu    = GcTb1.Text,
                            DonGiaId  = DgCb1.SelectedIndex != -1 ? DgIds[DgCb1.SelectedIndex] : (int?)null
                        };
                        db.ViTriBom_BaoCao.Add(newVt);
                    }
                    if (VtCb2.SelectedIndex > -1)
                    {
                        double dgv = 0;
                        double.TryParse(DgStTb2.Text.Replace(",", ""), out dgv);
                        double dg = 0;
                        double.TryParse(DgTtTb2.Text.Replace(",", ""), out dg);

                        var newVt = new ViTriBom_BaoCao
                        {
                            BaoCaoId  = newReport.Id,
                            ViTriId   = VtIds[VtCb2.SelectedIndex],
                            Tang      = TangTb2.Text.Length > 0 ? int.Parse(TangTb2.Text) : (int?)null,
                            SoLuong   = SlTb2.Text.Length > 0 ? double.Parse(SlTb2.Text) : (double?)null,
                            DonVi     = DvCb2.Text,
                            DonGiaVat = dgv,
                            DonGia    = dg,
                            GhiChu    = GcTb2.Text,
                            DonGiaId  = DgCb2.SelectedIndex != -1 ? DgIds[DgCb2.SelectedIndex] : (int?)null
                        };
                        db.ViTriBom_BaoCao.Add(newVt);
                    }
                    if (VtCb3.SelectedIndex > -1)
                    {
                        double dgv = 0;
                        double.TryParse(DgStTb3.Text.Replace(",", ""), out dgv);
                        double dg = 0;
                        double.TryParse(DgTtTb3.Text.Replace(",", ""), out dg);

                        var newVt = new ViTriBom_BaoCao
                        {
                            BaoCaoId  = newReport.Id,
                            ViTriId   = VtIds[VtCb3.SelectedIndex],
                            Tang      = TangTb3.Text.Length > 0 ? int.Parse(TangTb3.Text) : (int?)null,
                            SoLuong   = SlTb3.Text.Length > 0 ? double.Parse(SlTb3.Text) : (double?)null,
                            DonVi     = DvCb3.Text,
                            DonGiaVat = dgv,
                            DonGia    = dg,
                            GhiChu    = GcTb3.Text,
                            DonGiaId  = DgCb3.SelectedIndex != -1 ? DgIds[DgCb3.SelectedIndex] : (int?)null
                        };
                        db.ViTriBom_BaoCao.Add(newVt);
                    }

                    //Nhan luc
                    for (int i = 0; i < NhanLucGrid.Rows.Count; i++)
                    {
                        var row = NhanLucGrid.Rows[i];

                        if (row.Cells[0].Value == null)
                        {
                            continue;
                        }

                        var nvid = row.Cells[0].Value.ToString().Split('.')[0];
                        var bcnl = new NhanLuc_BaoCao
                        {
                            BaoCaoId     = newReport.Id,
                            NhanVienId   = int.Parse(nvid),
                            KhoiLuongBom = row.Cells[1].Value == null ? (double?)null : double.Parse(row.Cells[1].Value.ToString()),
                            DonGiaKhoi   = row.Cells[2].Value == null ? (int?)null : int.Parse(row.Cells[2].Value.ToString())
                        };
                        db.NhanLuc_BaoCao.Add(bcnl);
                    }
                    db.SaveChanges();
                }
                Cursor.Current = Cursors.Default;
                MessageBox.Show("Tạo báo cáo mới thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                Close();
            }
            catch (Exception ex)
            {
                Cursor.Current = Cursors.Default;
                MessageBox.Show(ex.GetBaseException().Message, "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
예제 #14
0
        private void AddBtn_Click(object sender, EventArgs e)
        {
            try
            {
                var id   = CtrIdTBox.Text.Trim();
                var name = CtrNameTBox.Text.Trim();
                if (id.Length == 0 || name.Length == 0)
                {
                    if (id.Length == 0)
                    {
                        CtrIdLbl.ForeColor = Color.Red;
                    }
                    else
                    {
                        CtrIdLbl.ForeColor = Color.Black;
                    }

                    if (name.Length == 0)
                    {
                        CtrNameLbl.ForeColor = Color.Red;
                    }
                    else
                    {
                        CtrNameLbl.ForeColor = Color.Black;
                    }
                }
                else
                {
                    DateTime ngayKy = new DateTime();
                    DateTime ngayTh = new DateTime();
                    var      cul    = CultureInfo.InvariantCulture;
                    var      dts    = DateTimeStyles.None;

                    if ((!DateTime.TryParseExact(NgayKyTBox.Text, "ddMMyyyy", cul, dts, out ngayKy) && NgayKyTBox.Text.Length > 0) ||
                        (!DateTime.TryParseExact(NgayThTBox.Text, "ddMMyyyy", cul, dts, out ngayTh) && NgayThTBox.Text.Length > 0))
                    {
                        MessageBox.Show("Ngày ký hoặc ngày thực hiện không đúng format ddMMyyyy", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }

                    Cursor.Current = Cursors.WaitCursor;
                    var db     = new CkpEntities();
                    var newCtr = new CongTrinh
                    {
                        Id              = id,
                        TenCongTrinh    = name,
                        DiaChi          = CtrDcTBox.Text.Length == 0 ? null : CtrDcTBox.Text.Trim(),
                        KhachHangId     = KhId,
                        SoHopDong       = SoHdTBox.Text.Length == 0 ? null : SoHdTBox.Text.Trim(),
                        NguoiPhuTrachId = NptCb.SelectedIndex == -1 ? (int?)null : int.Parse(NptCb.Text.Split('.')[0]),
                        NgayKyHD        = NgayKyTBox.Text.Length == 0 ? (DateTime?)null : ngayKy,
                        NgayThucHien    = NgayThTBox.Text.Length == 0 ? (DateTime?)null : ngayTh,
                        TrangThai       = 1,
                        NgayTao         = DateTime.Now,
                        NgaySuaCuoi     = DateTime.Now
                    };
                    db.CongTrinh.Add(newCtr);
                    db.SaveChanges();

                    Cursor.Current = Cursors.Default;
                    MessageBox.Show("Tạo mới thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                    parentForm.UpdateDataGrid();
                    Close();
                }
            }
            catch (Exception ex)
            {
                var exMsg = ex.GetBaseException().Message;
                if (exMsg.Contains("Violation of PRIMARY KEY constrain"))
                {
                    MessageBox.Show("Mã công trình đã tồn tại", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                else
                {
                    MessageBox.Show(ex.GetBaseException().Message, "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
예제 #15
0
        private void OkBtn_Click(object sender, EventArgs e)
        {
            try
            {
                var db   = new CkpEntities();
                var id   = IdTBox.Text;
                var name = NameTBox.Text;
                if (id.Length > 0 && name.Length > 0)
                {
                    Cursor.Current = Cursors.WaitCursor;

                    var newRow = new MayBom
                    {
                        Id          = id.Trim(),
                        TenBom      = name.Trim(),
                        LoaiBom     = TypeCBox.SelectedIndex == 0 ? 1 : 2,
                        TrangThai   = 1,
                        NgayTao     = DateTime.Now,
                        NgaySuaCuoi = DateTime.Now
                    };
                    db.MayBom.Add(newRow);
                    db.SaveChanges();

                    Cursor.Current = Cursors.Default;
                    MessageBox.Show("Tạo mới thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    parentForm.UpdateDataGrid();
                    Close();
                }
                else
                {
                    if (id.Length == 0)
                    {
                        IdLbl.ForeColor = Color.Red;
                    }
                    else
                    {
                        IdLbl.ForeColor = Color.Black;
                    }

                    if (id.Length == 0)
                    {
                        NameLbl.ForeColor = Color.Red;
                    }
                    else
                    {
                        NameLbl.ForeColor = Color.Black;
                    }
                }
            }
            catch (Exception ex)
            {
                var exMsg = ex.GetBaseException().Message;
                if (exMsg.Contains("Violation of PRIMARY KEY constrain"))
                {
                    MessageBox.Show("Mã máy bơm đã tồn tại", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                else
                {
                    MessageBox.Show(ex.GetBaseException().Message, "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
예제 #16
0
        private void OkBtn_Click(object sender, EventArgs e)
        {
            try
            {
                Cursor.Current = Cursors.WaitCursor;
                var db = new CkpEntities();
                if (TenDgTBox.Text.Length == 0)
                {
                    TenDgLbl.ForeColor = Color.Red;
                    return;
                }
                else
                {
                    TenDgLbl.ForeColor = Color.Black;
                }

                if (db.DonGiaBom.Where(dg => dg.CongTrinhId == CtrId && dg.TenDonGia == TenDgTBox.Text).Any())
                {
                    MessageBox.Show("Tên đơn giá này đã tồn tại", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                foreach (TextBox tb in this.Controls.OfType <TextBox>())
                {
                    int val = 0;
                    if (tb.Name == "TenDgTBox" || tb.Name == "CthucTBox" || tb.Name == "CtrTBox")
                    {
                        continue;
                    }
                    else
                    {
                        if (tb.Text.Length > 0 && !int.TryParse(tb.Text.Replace(",", ""), out val))
                        {
                            MessageBox.Show("Tất cả các thông tin số liệu phải là số", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            return;
                        }
                    }
                }

                var newDg = new DonGiaBom
                {
                    CongTrinhId     = CtrId,
                    TenDonGia       = TenDgTBox.Text,
                    DonGia          = Dg0TBox.Text.Length > 0 ? int.Parse(Dg0TBox.Text.Replace(",", "")) : (int?)null,
                    DonGiaVAT       = Dg1TBox.Text.Length > 0 ? int.Parse(Dg1TBox.Text.Replace(",", "")) : (int?)null,
                    VAT             = VatTBox.Text.Length > 0 ? int.Parse(VatTBox.Text) : (int?)null,
                    MinKlgBomCan    = MinBcTBox.Text.Length > 0 ? int.Parse(MinBcTBox.Text) : (int?)null,
                    MinKlgBomTinh   = MinBtTBox.Text.Length > 0 ? int.Parse(MinBtTBox.Text) : (int?)null,
                    CC1             = Cc1TBox.Text.Length > 0 ? int.Parse(Cc1TBox.Text.Replace(",", "")) : (int?)null,
                    TongCC2         = TgCc2TBox.Text.Length > 0 ? int.Parse(TgCc2TBox.Text.Replace(",", "")) : (int?)null,
                    PhanTramBackCC2 = PtCc2TBox.Text.Length > 0 ? int.Parse(PtCc2TBox.Text) : (int?)null,
                    TienBackCC2     = BackCc2TBox.Text.Length > 0 ? int.Parse(BackCc2TBox.Text.Replace(",", "")) : (int?)null,
                    NetCC2          = NetCc2TBox.Text.Length > 0 ? int.Parse(NetCc2TBox.Text.Replace(",", "")) : (int?)null,
                    TongThuVAT      = Kl1TBox.Text.Length > 0 ? int.Parse(Kl1TBox.Text.Replace(",", "")) : (int?)null,
                    TongVAT         = KlVatTBox.Text.Length > 0 ? int.Parse(KlVatTBox.Text.Replace(",", "")) : (int?)null,
                    TongThu         = Kl0TBox.Text.Length > 0 ? int.Parse(Kl0TBox.Text.Replace(",", "")) : (int?)null,
                    TongCC          = KlCcTBox.Text.Length > 0 ? int.Parse(KlCcTBox.Text.Replace(",", "")) : (int?)null,
                    CongThuc        = CthucTBox.Text,
                    GhiChu          = GcRtb.Text,
                    TrangThai       = 1,
                    NgayTao         = DateTime.Now,
                    NgaySuaCuoi     = DateTime.Now
                };
                db.DonGiaBom.Add(newDg);
                db.SaveChanges();

                Cursor.Current = Cursors.Default;
                MessageBox.Show("Tạo đơn giá thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                parentForm.UpdateDataGrid();
                Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.GetBaseException().Message, "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
예제 #17
0
        private void UpdateData()
        {
            try
            {
                Cursor.Current = Cursors.WaitCursor;

                var db   = new CkpEntities();
                var bc   = (from b in db.BaoCaoNgay where b.Id == BcId && b.TrangThai == 1 select b).FirstOrDefault();
                var vtbc = (from v in db.ViTriBom_BaoCao where v.BaoCaoId == BcId select v);
                var nlbc = (from n in db.NhanLuc_BaoCao where n.BaoCaoId == BcId select n);
                var cul  = CultureInfo.InvariantCulture;

                //Bao cao
                bc.NgayBaoCao    = DateTime.ParseExact(NgayBcTb.Text, "ddMMyyyy", cul);
                bc.NguoiBaoCaoId = NvIds[NgBcCb.SelectedIndex];
                bc.MayBomId      = BomIds[BomCb.SelectedIndex];
                bc.CongTrinhId   = CtrIds[CtrCb.SelectedIndex];
                bc.KhachHangId   = KhIds[KhCb.SelectedIndex];
                bc.GhiChu        = GcRtb.Text;
                bc.NgaySuaCuoi   = DateTime.Now;

                foreach (var vt in vtbc)
                {
                    db.ViTriBom_BaoCao.Remove(vt);
                }
                foreach (var nl in nlbc)
                {
                    db.NhanLuc_BaoCao.Remove(nl);
                }

                //Vi tri
                if (VtCb1.SelectedIndex > -1)
                {
                    double dgv = 0;
                    double.TryParse(DgStTb1.Text.Replace(",", ""), out dgv);
                    double dg = 0;
                    double.TryParse(DgTtTb1.Text.Replace(",", ""), out dg);

                    var newVt = new ViTriBom_BaoCao
                    {
                        BaoCaoId  = bc.Id,
                        ViTriId   = VtIds[VtCb1.SelectedIndex],
                        Tang      = int.Parse(TangTb1.Text),
                        SoLuong   = double.Parse(SlTb1.Text),
                        DonVi     = DvCb1.Text,
                        DonGiaVat = dgv,
                        DonGia    = dg,
                        GhiChu    = GcTb1.Text,
                        DonGiaId  = DgCb1.SelectedIndex != -1 ? DgIds[DgCb1.SelectedIndex] : (int?)null
                    };
                    db.ViTriBom_BaoCao.Add(newVt);
                }
                if (VtCb2.SelectedIndex > -1)
                {
                    double dgv = 0;
                    double.TryParse(DgStTb2.Text.Replace(",", ""), out dgv);
                    double dg = 0;
                    double.TryParse(DgTtTb2.Text.Replace(",", ""), out dg);

                    var newVt = new ViTriBom_BaoCao
                    {
                        BaoCaoId  = bc.Id,
                        ViTriId   = VtIds[VtCb2.SelectedIndex],
                        Tang      = int.Parse(TangTb2.Text),
                        SoLuong   = double.Parse(SlTb2.Text),
                        DonVi     = DvCb2.Text,
                        DonGiaVat = dgv,
                        DonGia    = dg,
                        GhiChu    = GcTb2.Text,
                        DonGiaId  = DgCb2.SelectedIndex != -1 ? DgIds[DgCb2.SelectedIndex] : (int?)null
                    };
                    db.ViTriBom_BaoCao.Add(newVt);
                }
                if (VtCb3.SelectedIndex > -1)
                {
                    double dgv = 0;
                    double.TryParse(DgStTb3.Text.Replace(",", ""), out dgv);
                    double dg = 0;
                    double.TryParse(DgTtTb3.Text.Replace(",", ""), out dg);

                    var newVt = new ViTriBom_BaoCao
                    {
                        BaoCaoId  = bc.Id,
                        ViTriId   = VtIds[VtCb3.SelectedIndex],
                        Tang      = int.Parse(TangTb3.Text),
                        SoLuong   = double.Parse(SlTb3.Text),
                        DonVi     = DvCb3.Text,
                        DonGiaVat = dgv,
                        DonGia    = dg,
                        GhiChu    = GcTb3.Text,
                        DonGiaId  = DgCb3.SelectedIndex != -1 ? DgIds[DgCb3.SelectedIndex] : (int?)null
                    };
                    db.ViTriBom_BaoCao.Add(newVt);
                }

                //Nhan luc
                for (int i = 0; i < NhanLucGrid.Rows.Count; i++)
                {
                    var row = NhanLucGrid.Rows[i];

                    if (row.Cells[0].Value == null)
                    {
                        continue;
                    }

                    var nvid = row.Cells[0].Value.ToString().Split('.')[0];
                    var bcnl = new NhanLuc_BaoCao
                    {
                        BaoCaoId     = bc.Id,
                        NhanVienId   = int.Parse(nvid),
                        KhoiLuongBom = row.Cells[1].Value == null ? (double?)null : double.Parse(row.Cells[1].Value.ToString()),
                        DonGiaKhoi   = row.Cells[2].Value == null ? (int?)null : int.Parse(row.Cells[2].Value.ToString())
                    };
                    db.NhanLuc_BaoCao.Add(bcnl);
                }

                db.SaveChanges();
                Cursor.Current = Cursors.Default;
                MessageBox.Show("Cập nhật dữ liệu thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                parentForm.UpdateSearchResult();
                Close();
            }
            catch (Exception ex)
            {
                Cursor.Current = Cursors.Default;
                MessageBox.Show(ex.GetBaseException().Message, "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }