public static void insert(P_DonDatHang obkPDonDatHang,List<P_DonDatHangCT> lstDonDatHangCts ,List<P_DonDatHang_CT_Phieu> lstPhieu = null)
 {
     using (var model = ModelConnector.Connector())
     {
         model.P_DonDatHang.Add(obkPDonDatHang);
         model.P_DonDatHangCT.AddRange(lstDonDatHangCts);
         if (lstPhieu != null)
             model.P_DonDatHang_CT_Phieu.AddRange(lstPhieu);
         model.SaveChanges();
     }
 }
 public static void update(P_DonDatHang obkPDonDatHang, List<P_DonDatHangCT> lstDonDatHangCts, List<P_DonDatHang_CT_Phieu> lstPhieu = null)
 {
     using (var model = ModelConnector.Connector())
     {
         model.P_DonDatHangCT.RemoveRange(model.P_DonDatHangCT.Where(a => a.SoDonDatHang.Equals(obkPDonDatHang.SoDonDatHang)).Select(a => a));
         model.P_DonDatHang_CT_Phieu.RemoveRange(model.P_DonDatHang_CT_Phieu.Where(a => a.SoDonDatHang.Equals(obkPDonDatHang.SoDonDatHang)).Select(a => a));
         //model.P_DonDatHang_CT_Phieu.Where(a => a.SoDonDatHang == obkPDonDatHang.SoDonDatHang).ToList().ForEach(a => a.IsDel = true);
         model.Entry(obkPDonDatHang).State = System.Data.Entity.EntityState.Modified;
         if(lstPhieu!=null)
         {
             model.P_DonDatHang_CT_Phieu.AddRange(lstPhieu);
         }
         model.P_DonDatHangCT.AddRange(lstDonDatHangCts);
         model.SaveChanges();
     }
 }
 public fDonDatHang(bool updateDonDatHang=false,P_DonDatHang obj=null)
 {
     InitializeComponent();
     _updateDonDatHang = updateDonDatHang;
     dateNgayGiaoDich.DateTime = DateTime.Now;
     txtGhiChu1.Text = "- Đơn giá đã bao gồm thuế GTGT 10% và các loại thuế phí theo qui định hiện hành.";
     txtGhiChu2.Text = "- Chất lượng: theo tiêu chuẩn chất lượng xăng dầu Việt Nam.";
     txtGhiChu3.Text = "- Thời gian nhận hàng từ ngày " + DateTime.Now.ToString("dd/MM/yyyy");
     txtGhiChu4.Text = "- Thời hạn thanh toán: trước khi nhận phiếu xuất kho";
     txtGhiChu5.Text = "- Phương tiện vận chuyển: Sà lan";
     load_data_lk();
     int numDonDatHang = ADonDatHang.get_count_DonDatHang();
     _numDonDatHang = string.Format("{0}-{1}-{2}/BT", TimeServer.Day, TimeServer.Month, numDonDatHang.ToString("00"));
     txtSoDonHang.Text = _numDonDatHang;
     path_folder = Local_Params.Path_File + @"\" + Local_Params.TimeServer.ToString("yyyy") + @"\" + Local_Params.TimeServer.ToString("MM") + @"\" + Local_Params.TimeServer.ToString("dd") + @"\" + txtSoDonHang.Text.Replace('/', '-');
     repoDatePhieu.NullDate = Local_Params.TimeServer;
     if (_updateDonDatHang)
     {
         objPDonDatHang = obj;
         load_DonDatHang();
         return;
     }
 }
 private void btnPrint_Click(object sender, EventArgs e)
 {
     gridViewPhieu.OptionsView.NewItemRowPosition = NewItemRowPosition.None; gridDonDatHang.OptionsView.NewItemRowPosition = NewItemRowPosition.None;
     if (check_detail_on_form() == false)
     { gridViewPhieu.OptionsView.NewItemRowPosition = NewItemRowPosition.Bottom;
         gridDonDatHang.OptionsView.NewItemRowPosition = NewItemRowPosition.Bottom; return; }
     lstPDonDatHangCt = new List<P_DonDatHangCT>();
     lstPDonDatHangCtPhieu = new List<P_DonDatHang_CT_Phieu>();
     objPDonDatHang = new P_DonDatHang();
     set_Object();
     print_DonDatHang();
     gridViewPhieu.OptionsView.NewItemRowPosition = NewItemRowPosition.Bottom; gridDonDatHang.OptionsView.NewItemRowPosition = NewItemRowPosition.Bottom;
 }
        void insert_DonDatHang()
        {
            objPDonDatHang = new P_DonDatHang();
            lstPDonDatHangCt = new List<P_DonDatHangCT>();
            lstPDonDatHangCtPhieu = new List<P_DonDatHang_CT_Phieu>();

            set_Object();
            ADonDatHang.insert(objPDonDatHang, lstPDonDatHangCt,lstPDonDatHangCtPhieu);
        }
        private void gridView_DoubleClick(object sender, EventArgs e)
        {
            try
            {
                int row = gridView.FocusedRowHandle;
                if (row < 0)
                    return;
                objPDonDatHang = new P_DonDatHang();

                objPDonDatHang = (P_DonDatHang) gridView.GetFocusedRow();
                fDonDatHang f = new fDonDatHang(true,objPDonDatHang);
                f.WindowState = FormWindowState.Maximized;
                f.ShowDialog();
            }
            catch (Exception ex)
            {
                commons.ShowAlert(ex.Message, 2);
            }
        }