private void saveFileDialog_FileOk(object sender, CancelEventArgs e) { try { Customer mCus = new KhachHangLDM().GetElement(mConsume.CustomerID.Value); var doc = DocX.Load(@"..\..\doc\HoaDon.docx"); doc.ReplaceText("<MaSo>", (MyRandom.RandomString(9) + mConsume.ID)); doc.ReplaceText("<TenKhachHang>", mCus.User.DisplayName); doc.ReplaceText("<SoCMT>", mCus.PassportID); doc.ReplaceText("<DiaChi>", mCus.User.Address); doc.ReplaceText("<ThoiGian>", thoiGian); doc.ReplaceText("<LuongDienTieuThu>", mConsume.ElectricConsume.ToString() + " (Kwh)"); doc.ReplaceText("<LuongNuocTieuThu>", mConsume.WaterConsume.ToString() + " (khối)"); doc.ReplaceText("<TongTienDien>", (mConsume.ElectricConsume.Value * mPrice.ElectricPrice.Value).ToString("#,###")); doc.ReplaceText("<TongTienNuoc>", (mConsume.WaterConsume.Value * mPrice.WaterPrice.Value).ToString("#,###")); doc.ReplaceText("<TongCong>", ((mConsume.WaterConsume.Value * mPrice.WaterPrice.Value) + (mConsume.ElectricConsume.Value * mPrice.ElectricPrice.Value)).ToString("#,###")); doc.ReplaceText("<Ngay>", DateTime.Now.Day.ToString()); doc.ReplaceText("<Thang>", DateTime.Now.Month.ToString()); doc.ReplaceText("<Nam>", DateTime.Now.Year.ToString()); Stream stream = saveFileDialog.OpenFile(); StreamWriter sw = new StreamWriter(stream); doc.SaveAs(stream); sw.Close(); stream.Close(); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void btnLuuLai_Click(object sender, EventArgs e) { try { Customer newCustomer = new Customer(); newCustomer.User = new User(); erpThemKhachHang.Clear(); if (string.IsNullOrEmpty(txtTenDangNhap.Text.Trim())) { erpThemKhachHang.SetError(txtTenDangNhap, "Vui lòng điền trường này!"); txtTenDangNhap.Focus(); } else { if (new UserLDM().isDuplicateUserName(txtTenDangNhap.Text.Trim())) { erpThemKhachHang.SetError(txtTenDangNhap, "Tên đăng nhập đã tồn tại!"); txtTenDangNhap.Focus(); } else { newCustomer.User.UserName = txtTenDangNhap.Text; if (string.IsNullOrEmpty(txtMatKhau.Text.Trim())) { erpThemKhachHang.SetError(txtMatKhau, "Vui lòng điền trường này!"); txtMatKhau.Focus(); } else { if (string.IsNullOrEmpty(txtNhapLaiMatKhau.Text.Trim())) { erpThemKhachHang.SetError(txtNhapLaiMatKhau, "Vui lòng điền trường này!"); txtNhapLaiMatKhau.Focus(); } else { if (!txtMatKhau.Text.Equals(txtNhapLaiMatKhau.Text)) { erpThemKhachHang.SetError(txtNhapLaiMatKhau, "Nhập lại mật khẩu không khớp!"); txtNhapLaiMatKhau.Focus(); } else { newCustomer.User.Password = Commons.En_Decrypt.Encrypt(txtMatKhau.Text); if (string.IsNullOrEmpty(txtTenHienThi.Text.Trim())) { erpThemKhachHang.SetError(txtTenHienThi, "Vui lòng điền trường này!"); txtTenHienThi.Focus(); } else { newCustomer.User.DisplayName = txtTenHienThi.Text; if (dtpNgaySinh.Value == null) { erpThemKhachHang.SetError(dtpNgaySinh, "Vui lòng điền trường này!"); dtpNgaySinh.Focus(); } else { newCustomer.User.DateOfBirth = dtpNgaySinh.Value; if (string.IsNullOrEmpty(txtSoCMT.Text.Trim())) { erpThemKhachHang.SetError(txtSoCMT, "Vui lòng điền trường này!"); txtSoCMT.Focus(); } else { newCustomer.PassportID = txtSoCMT.Text.Trim(); if (!rdoNam.Checked && !rdoNu.Checked) { erpThemKhachHang.SetError(rdoNu, "Vui lòng điền trường này!"); } else { newCustomer.User.Gender = rdoNam.Checked; if (string.IsNullOrEmpty(txtSoDienThoai.Text.Trim())) { erpThemKhachHang.SetError(txtSoDienThoai, "Vui lòng điền trường này!"); txtSoDienThoai.Focus(); } else { newCustomer.User.Phone = txtSoDienThoai.Text; if (string.IsNullOrEmpty(txtEmail.Text.Trim())) { erpThemKhachHang.SetError(txtEmail, "Vui lòng điền trường này!"); txtEmail.Focus(); } else { Regex mRegxExpression; mRegxExpression = new Regex(@"^([a-zA-Z0-9_\-])([a-zA-Z0-9_\-\.]*)@(\[((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}|((([a-zA-Z0-9\-]+)\.)+))([a-zA-Z]{2,}|(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\])$"); if (!mRegxExpression.IsMatch(txtEmail.Text.Trim())) { erpThemKhachHang.SetError(txtEmail, "Địa chỉ email không hợp lệ!"); txtEmail.Focus(); } else { newCustomer.User.Email = txtEmail.Text.Trim(); if (string.IsNullOrEmpty(txtDiaChi.Text.Trim())) { erpThemKhachHang.SetError(txtDiaChi, "Vui lòng điền trường này!"); txtDiaChi.Focus(); } else { newCustomer.User.Address = txtDiaChi.Text.Trim(); if (cboPrice.SelectedIndex == -1) { erpThemKhachHang.SetError(cboPrice, "Vui lòng điền trường này!"); cboPrice.Focus(); } else { newCustomer.PriceID = int.Parse(cboPrice.SelectedValue.ToString()); newCustomer.User.isPay = false; newCustomer.User.CreatedByID = mUser.ID; newCustomer.User.CreatedDate = DateTime.Now.Date; newCustomer.CreatedByID = mUser.ID; newCustomer.CreatedDate = DateTime.Now.Date; newCustomer.User.isDelete = false; newCustomer.User.isAdmin = 3; // khách hàng Customer CustomerResult = new KhachHangLDM().Insert(newCustomer); if (CustomerResult != null) { MessageBox.Show("Thêm khách hàng thành công!"); this.UCCuaSoChinh.ReLoadDataKhachHang(); } else { MessageBox.Show("Thêm khách hàng thất bại!"); } this.Close(); } } } } } } } } } } } } } } } catch (Exception ex) { MessageBox.Show(ex.Message); } }