Exemplo n.º 1
0
        private void button2_Click(object sender, EventArgs e)
        {
            try
            {
                using (var db = new RestaurantManagerDataEntities())
                {
                    int idpnhap  = int.Parse(txtid.Text);
                    var ngaynhap = dtngaynhap.Value;
                    int.TryParse(lueDONGIAO.EditValue.ToString(), out int idgiaohang);
                    int.TryParse(lueStorekeeper.EditValue.ToString(), out int thukho);
                    string thukhoName = lueStorekeeper.Text;
                    string nguoigiao  = txtNguoiGiao.Text;
                    string nguoinhap  = txtNguoiNhan.Text;

                    if (ngaynhap == null)
                    {
                        XtraMessageBox.Show("Bạn chưa chọn ngày nhập!", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        return;
                    }
                    if (lstD_PNHAP_ViewModel.Count == 0)
                    {
                        XtraMessageBox.Show("Bạn chưa nhập hàng hóa!", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        return;
                    }

                    if (lstD_PNHAP_ViewModel.Count() == 0)
                    {
                        XtraMessageBox.Show("Bạn chưa nhập hàng hóa!", "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        return;
                    }
                    var model   = new PNHAP_ViewModel();
                    var nameLog = Properties.Settings.Default.NameLog;
                    model.idpnhap       = idpnhap;
                    model.idpgiao       = idgiaohang;
                    model.ngaynhap      = ngaynhap;
                    model.thukho        = thukhoName;
                    model.nguoilapphieu = nameLog;
                    model.nguoigiao     = nameLog;
                    var res = new PNHAPBll().savePNHAP(model, lstD_PNHAP_ViewModel, Properties.Settings.Default.NameLog);
                    if (res != "success")
                    {
                        XtraMessageBox.Show(res, "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        return;
                    }
                    XtraMessageBox.Show("Thêm phiếu giao hàng thành công!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    this.Close();
                }
            }
            catch (Exception ex)
            {
                XtraMessageBox.Show(ex.Message, "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="obj"></param>
        /// <param name="data"></param>
        public void PrintPNHAP(PNHAP_ViewModel obj, List <D_PNHAP_ViewModel> data)
        {
            ReportPNHAP report = new ReportPNHAP();

            //Hide paramater
            foreach (DevExpress.XtraReports.Parameters.Parameter p in report.Parameters)
            {
                p.Visible = false;
            }
            //Init data report
            report.InitData(obj, data);
            documentViewer1.DocumentSource = report;
            report.CreateDocument();
        }
Exemplo n.º 3
0
 public void InitData(PNHAP_ViewModel master, List <D_PNHAP_ViewModel> detail)
 {
     using (var db = new RestaurantManagerDataEntities())
     {
         var toDay = DateTime.Now;
         lblidpnhap.Text              = master.idpnhap.ToString();
         lblidgiaohang.Text           = master.idpgiao.ToString();
         lblngaynhap.Text             = string.Format("{0}/{1}/{2}", master.ngaynhap.Value.Day, master.ngaynhap.Value.Month, master.ngaynhap.Value.Year);
         lblnguoigiao.Text            = master.nguoigiao;
         lblnguoilap.Text             = master.nguoilapphieu;
         lblthukho.Text               = master.thukho;
         objectDataSource2.DataSource = detail;
         lblFooterDate.Text           = string.Format("Ngày {0} tháng {1} năm {2}", toDay.Day, toDay.Month, toDay.Year);
     }
 }
Exemplo n.º 4
0
        public string savePNHAP(PNHAP_ViewModel model, List <D_PNHAP_ViewModel> lstDetail, string nameLog)
        {
            using (var db = new RestaurantManagerDataEntities())
            {
                using (var transaction = db.Database.BeginTransaction())
                {
                    try
                    {
                        //master
                        var check = db.PNHAPs.FirstOrDefault(e => e.idpnhap == model.idpnhap);
                        if (check == null)
                        {
                            check            = new PNHAP();
                            check.CreateBy   = nameLog;
                            check.CreateDate = DateTime.Now;
                            db.PNHAPs.Add(check);
                        }
                        else
                        {
                            check.ModifyBy        = nameLog;
                            check.ModifyDate      = DateTime.Now;
                            db.Entry(check).State = EntityState.Modified;
                        }
                        check.thukho        = model.thukho;
                        check.ngaynhap      = model.ngaynhap;
                        check.idpgiao       = model.idpgiao;
                        check.nguoigiao     = model.nguoigiao;
                        check.nguoilapphieu = nameLog;
                        db.SaveChanges();

                        //detail
                        var details = db.D_PNHAP.Where(p => p.idpnhap == check.idpnhap).ToList();
                        if (details.Count() > 0)
                        {
                            db.D_PNHAP.RemoveRange(details);
                        }
                        db.SaveChanges();
                        foreach (var item in lstDetail)
                        {
                            var detail = new D_PNHAP
                            {
                                idpnhap    = check.idpnhap,
                                idhang     = item.idhang,
                                slgiao     = item.slgiao,
                                slnhan     = item.slnhan,
                                CreateBy   = nameLog,
                                CreateDate = DateTime.Now,
                            };
                            db.D_PNHAP.Add(detail);
                        }
                        db.SaveChanges();
                        transaction.Commit();
                        return("success");
                    }
                    catch (Exception ex)
                    {
                        transaction.Rollback();
                        return(ex.Message);
                    }
                }
            }
        }