Example #1
0
    public string ValidateAllList()
    {
        if (ProductCodeInList.Count == 0)
        {
            return("Không có sản phẩm đầu vào.");
        }

        if (ProductCodeOutList.Count == 0)
        {
            return("Không có sản phẩm đầu ra.");
        }

        if (DINInList.Count == 0)
        {
            return("Không có túi máu đầu vào.");
        }

        ReceiptBLL.ValidateOnTherapyReceipt(ProductCodeInList, ProductCodeOutList);

        if (ProductCodeInList.Where(r => ProductCodeOutList.Contains(r)).Count() != 0)
        {
            return("Danh sách sản phẩm đầu ra và đầu vào có sản phẩm trùng.");
        }

        return("");
    }
Example #2
0
    public List <string> AddProductCodeOut(string productCode)
    {
        if (ProductCodeInList.Contains(productCode))
        {
            throw new Exception("Sản phẩm đầu ra đã có trong danh sách đầu vào.");
        }

        if (ProductCodeOutList.Contains(productCode))
        {
            throw new Exception("Sản phẩm đầu ra đã có trong danh sách đầu ra.");
        }

        List <string> tempList = ProductCodeOutList.ToList();

        tempList.Add(productCode);
        ReceiptBLL.ValidateOnTherapyReceipt(ProductCodeInList, tempList);

        RedBloodDataContext db = new RedBloodDataContext();
        int count = db.Packs.Where(r => r.ProductCode == productCode && DINInList.Contains(r.DIN)).Count();

        if (count > 0)
        {
            throw new Exception("Sản phẩm đầu ra đã sản xuất.");
        }

        ProductCodeOutList.Add(productCode);

        return(ProductCodeOutList);
    }
Example #3
0
 private void btnOk_Click(object sender, EventArgs e)
 {
     using (ReceiptBLL receiptBLL = new ReceiptBLL())
     {
         if (remainingAmount >= 0)
         {
             receipt.GivenAmount  = Convert.ToDecimal(txtGivenAmount.Text);
             this.retrunReference = receiptBLL.AddReceiptDetails(receipt);
             var returnValue = Convert.ToInt32(this.retrunReference);
             if (returnValue > 0)
             {
                 MessageBox.Show("Receipt printed succesful");
                 this.retrunValue    = returnValue;
                 receiptForm.Enabled = true;
                 this.DialogResult   = DialogResult.OK;
                 this.Close();
             }
             else
             {
                 this.retrunValue = 0;
                 MessageBox.Show("Receipt print faild");
             }
         }
         else
         {
             this.retrunValue = 0;
             MessageBox.Show("Customer Given amount should be greater than receipt amount");
         }
     }
 }
    protected void btnDelete_Click(object sender, EventArgs e)
    {
        if (ReceiptID != Guid.Empty)
        {
            ReceiptBLL.Delete(ReceiptID);

            ReceiptID = Guid.Empty;
            GridView1.DataBind();
        }
    }
Example #5
0
        partial void OnNameChanging(string value)
        {
            if (string.IsNullOrEmpty(value.Trim()))
            {
                throw new Exception("Nhập tên.");
            }

            if (ReceiptBLL.IsExistName(value.Trim(), ID))
            {
                throw new Exception("Trùng tên");
            }
        }
Example #6
0
    public Guid InsertOrUpdate(Guid ID, Func <Receipt, Receipt> loadFromGUI)
    {
        RedBloodDataContext db = new RedBloodDataContext();
        Receipt             r;

        if (ID == Guid.Empty)
        {
            r = new Receipt();
            db.Receipts.InsertOnSubmit(r);
        }
        else
        {
            r = ReceiptBLL.Get(ID, db);
        }

        loadFromGUI(r);

        //Product In
        IEnumerable <ReceiptProduct> existingProductCodeInList = r.ReceiptProducts.Where(r1 => r1.Type == ReceiptProduct.TypeX.In);

        db.ReceiptProducts.DeleteAllOnSubmit(
            existingProductCodeInList.Where(r1 => !ProductCodeInList.Contains(r1.ProductCode))
            );

        r.ReceiptProducts.AddRange(
            ProductCodeInList
            .Except(existingProductCodeInList.Select(r1 => r1.ProductCode))
            .Select(r1 => new ReceiptProduct()
        {
            ProductCode = r1, Type = ReceiptProduct.TypeX.In
        })
            );

        //Product Out
        IEnumerable <ReceiptProduct> existingProductCodeOutList = r.ReceiptProducts.Where(r1 => r1.Type == ReceiptProduct.TypeX.Out);

        db.ReceiptProducts.DeleteAllOnSubmit(
            existingProductCodeOutList.Where(r1 => !ProductCodeOutList.Contains(r1.ProductCode))
            );

        r.ReceiptProducts.AddRange(
            ProductCodeOutList
            .Except(existingProductCodeOutList.Select(r1 => r1.ProductCode))
            .Select(r1 => new ReceiptProduct()
        {
            Product = ProductBLL.Get(db, r1), Type = ReceiptProduct.TypeX.Out
        })
            );

        db.SubmitChanges();
        return(r.ID);
    }
Example #7
0
 private void LoadReceiptType()
 {
     try
     {
         ReceiptBLL receiptBLL = new ReceiptBLL();
         cbxTypereceipt.DataSource    = receiptBLL.loadreceipttype();
         cbxTypereceipt.DisplayMember = "nametype";
         cbxTypereceipt.ValueMember   = "idtype";
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message, "ERROR");
     }
 }
        private void phoneNumberValidateValue()
        {
            this.BusinessPartnerFormFieldValidation();
            using (ReceiptBLL receipt = new ReceiptBLL())
            {
                BusinessPartnerContactDetails contact = this.contacts.Where(selectContact => selectContact.PhoneNumber.Trim().ToUpper() == cmbPhoneNumber.Text.Trim().ToUpper()).FirstOrDefault();
                if (contact != null)
                {
                    this.selectedBSP = receipt.GetBusinessPartnerByBSPId(contact.BusinessPartnerId);

                    txtName.Text    = this.selectedBSP.Name;
                    txtAddress.Text = this.selectedBSP.addresses.First().Address;
                }
            }
        }
Example #9
0
        public bool RedeemPoints(ReceiptBLL rb)
        {
            SqlConnection con       = new SqlConnection(myconnstring);
            bool          isSuccess = false;

            try
            {
                con.Open();

                string     sql = "INSERT INTO Receipts(ReceiptNo,BillAmount,PointsAdded,Operation,PointsRedeemed,CustomerID,date) VALUES(@ReceiptNo,@BillAmount,@PointsAdded,@Operation,@PointsRedeemed,@CustomerID,@date) ";
                SqlCommand cmd = new SqlCommand(sql, con);
                cmd.Parameters.AddWithValue("@ReceiptNo", rb.ReceiptNo);
                cmd.Parameters.AddWithValue("@BillAmount", rb.BillAmount);
                cmd.Parameters.AddWithValue("@PointsAdded", rb.PointsAdded);
                cmd.Parameters.AddWithValue("@Operation", rb.Operation);
                cmd.Parameters.AddWithValue("@PointsRedeemed", rb.PointsRedeemed);
                cmd.Parameters.AddWithValue("@CustomerID", rb.CustomerID);
                cmd.Parameters.AddWithValue("@date", rb.date);

                int row = cmd.ExecuteNonQuery();


                string     sql1 = "UPDATE Customers SET PointsAvailable=PointsAvailable - @PointsRedeemed WHERE CustomerID=@CustomerID";
                SqlCommand cmd1 = new SqlCommand(sql1, con);
                cmd1.Parameters.AddWithValue("@PointsRedeemed", rb.PointsRedeemed);
                cmd1.Parameters.AddWithValue("@CustomerID", rb.CustomerID);

                cmd1.ExecuteNonQuery();
                if (row > 0)
                {
                    isSuccess = true;
                }
                else
                {
                    isSuccess = false;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                con.Close();
            }

            return(isSuccess);
        }
Example #10
0
 private void btnConfirmreceipt_Click(object sender, EventArgs e)
 {
     try
     {
         if (cbxActionreceipt.SelectedIndex == 0)
         {
             receiptBLL = new ReceiptBLL();
             receiptBLL.createreceipt(userBLL.getid(), DateTime.ParseExact(lbltime.Text, "dd/MM/yyyy HH:mm", CultureInfo.InvariantCulture), Convert.ToInt32(cbxTypereceipt.SelectedValue));
             ReceiptDetail formreceiptdetail = new ReceiptDetail(receiptBLL);
             formreceiptdetail.ShowDialog();
             loadlistreceipt();
         }
         else
         {
             if (dgvReceipt.CurrentCell != null)
             {
                 DialogResult result = MessageBox.Show("Do you want to cancel this receipt?", "NOTICE", MessageBoxButtons.YesNo);
                 if (result == DialogResult.Yes)
                 {
                     DataTable dt        = new DataTable();
                     int       rownumber = dgvReceipt.CurrentCell.RowIndex;
                     dt = (DataTable)dgvReceipt.DataSource;
                     string idreceipt = dt.Rows[rownumber][0].ToString();
                     receiptBLL.cancelreceipt(idreceipt);
                     MessageBox.Show("Receipt " + idreceipt + " has been cancel", "NOTICE");
                     loadlistreceipt();
                 }
                 else
                 {
                 }
             }
             else
             {
                 MessageBox.Show("There is no receipt to cancel!", "ERROR");
             }
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message, "ERROR");
     }
 }
Example #11
0
        public bool UpdatePoint(ReceiptBLL rb)
        {
            SqlConnection con       = new SqlConnection(myconnstring);
            bool          isSuccess = false;

            try
            {
                con.Open();
                string     sql = "UPDATE Receipts SET ReceiptNo=@ReceiptNo ,BillAmount=@BillAmount, PointsAdded=@PointsAdded, Operation=@Operation, PointsRedeemed=@PointsRedeemed, CustomerID=@CustomerID,date = @date WHERE CustomerID=@CustomerID";
                SqlCommand cmd = new SqlCommand(sql, con);
                cmd.Parameters.AddWithValue("@ReceiptNo", rb.ReceiptNo);
                cmd.Parameters.AddWithValue("@BillAmount", rb.BillAmount);
                cmd.Parameters.AddWithValue("@PointsAdded", rb.PointsAdded);
                cmd.Parameters.AddWithValue("@Operation", rb.Operation);
                cmd.Parameters.AddWithValue("@PointsRedeemed", rb.PointsRedeemed);
                cmd.Parameters.AddWithValue("@CustomerID", rb.CustomerID);
                cmd.Parameters.AddWithValue("@date", rb.date);

                int row = cmd.ExecuteNonQuery();

                if (row > 0)
                {
                    isSuccess = true;
                }
                else
                {
                    isSuccess = false;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                con.Close();
            }



            return(isSuccess);
        }
Example #12
0
    public List <string> AddProductCodeIn(string productCode)
    {
        if (ProductCodeInList.Contains(productCode))
        {
            throw new Exception("Sản phẩm đầu vào đã có trong danh sách đầu vào.");
        }

        if (ProductCodeOutList.Contains(productCode))
        {
            throw new Exception("Sản phẩm đầu vào đã có trong danh sách đầu ra.");
        }

        if (ProductCodeInList.Count == 1)
        {
            throw new Exception("Sản phẩm đầu vào chỉ được 1 loại.");
        }

        List <string> tempList = ProductCodeInList.ToList();

        tempList.Add(productCode);
        ReceiptBLL.ValidateOnTherapyReceipt(tempList, ProductCodeOutList);

        RedBloodDataContext db = new RedBloodDataContext();
        int count = db.Packs.Where(r => r.ProductCode == productCode && DINInList.Contains(r.DIN)).Count();

        if (count < DINInList.Count)
        {
            throw new Exception("Sản phẩm đầu vào không có túi máu.");
        }

        if (count > DINInList.Count)
        {
            throw new Exception("Sản phẩm đầu vào có túi máu bị trùng dữ liệu.");
        }


        ProductCodeInList.Add(productCode);

        return(ProductCodeInList);
    }
    public void DisplayToGUI()
    {
        Receipt e = ReceiptBLL.Get(ReceiptID);

        if (e == null)
        {
            e = new Receipt();
            ProductCodeInList.Clear();
            ProductCodeOutList.Clear();
            rdbProductCodeIn.Checked = true;
        }
        else
        {
            ProductCodeInList  = e.ReceiptProducts.Where(r => r.Type == ReceiptProduct.TypeX.In).Select(r => r.ProductCode).ToList();
            ProductCodeOutList = e.ReceiptProducts.Where(r => r.Type == ReceiptProduct.TypeX.Out).Select(r => r.ProductCode).ToList();
        }

        txtName.Text = e.Name;
        txtNote.Text = e.Note;

        DataListProductIn.DataBind();
        DataListProductOut.DataBind();
    }
        private void cmbPhoneNumber_KeyDown(object sender, KeyEventArgs e)
        {
            string text = cmbPhoneNumber.Text.Trim();

            if (text.Length > 3)
            {
                using (ReceiptBLL recipt = new ReceiptBLL())
                {
                    this.contacts = recipt.GetContact(text);
                    string[] stringContact = this.contacts.Select(contact => contact.PhoneNumber).ToArray();
                    if (stringContact.Length > 0)
                    {
                        cmbPhoneNumber.AutoCompleteCustomSource.AddRange(stringContact);
                    }
                }
            }
            if (e.KeyCode == Keys.Enter &&
                text.Length > 9)
            {
                this.phoneNumberValidateValue();
                this.BusinessPartnerFormFieldValidation();
                this.txtName.Focus();
            }
        }
Example #15
0
        public void makepayment()
        {
            Console.Clear();
            System.Console.WriteLine("Payment\n\n");

            ReceiptBO  rec  = new ReceiptBO();
            ReceiptBLL recB = new ReceiptBLL();

            int recid = recB.readId();

            DateTime thisDay = DateTime.Today;

            System.Console.Write("Enter SaleID: ");
            int    saleid;
            String c = System.Console.ReadLine();

            if (c.Length != 0)
            {
                saleid = int.Parse(c);
            }
            else
            {
                saleid = 0;
            }

            SaleBLL saleB = new SaleBLL();
            SaleBO  saleO = saleB.find(saleid);

            CustomerBLL custB = new CustomerBLL();
            CustomerBO  custO = custB.find(saleO.Custid);

            if (saleO.Orderid != 0)
            {
                double amountpaid = recB.amountpaid(saleid);
                double remain     = saleO.Total - amountpaid;
                System.Console.WriteLine("Customer Name: " + custO.Name);
                System.Console.WriteLine("Total Sales Amount: " + saleO.Total);
                System.Console.WriteLine("Amount paid: " + amountpaid);
                System.Console.WriteLine("Remaining Amount: " + remain);
                System.Console.Write("Enter Amount: ");

                double amt;
                c = System.Console.ReadLine();
                if (c.Length != 0)
                {
                    amt = double.Parse(c);
                }
                else
                {
                    amt = 0;
                }

                while (amt < 0 || amt > remain)
                {
                    System.Console.Write("InValid Amount! Enter again: ");
                    c = System.Console.ReadLine();
                    if (c.Length != 0)
                    {
                        amt = double.Parse(c);
                    }
                    else
                    {
                        amt = 0;
                    }
                }

                if (remain > 0)
                {
                    custO.Amount = custO.Amount - amt;
                    custB.modify(custO);

                    rec.Receiptid  = recid;
                    rec.Orderid    = saleid;
                    rec.Amountpaid = amt;
                    recB.save(rec);
                }
                else
                {
                    System.Console.WriteLine("Back to Main Menu...");
                    System.Threading.Thread.Sleep(2000);
                }
            }
        }
Example #16
0
 public ReceiptDetail(ReceiptBLL receiptBLL_)
 {
     InitializeComponent();
     receiptBLL = receiptBLL_;
 }
        private void btnCustomerAdd_Click(object sender, EventArgs e)
        {
            isReceiptFormEnable = false;
            if (!isBusinessPartnerAvailable)
            {
                if (txtName.Text.Trim().Length > 0 &&
                    txtAddress.Text.Trim().Length > 0 &&
                    cmbPhoneNumber.Text.Trim().Length >= 10 &&
                    cmbPhoneNumber.Text.Trim().Length <= 12)
                {
                    BusinessPartnerVM bspVM = new BusinessPartnerVM()
                    {
                        contacts  = new List <BusinessPartnerContactDetails>(),
                        addresses = new List <BusinessPartnerAddressDetails>()
                    };
                    BusinessPartnerContactDetails bspContactVM;
                    BusinessPartnerAddressDetails bspAddressVM = new BusinessPartnerAddressDetails();
                    bspContactVM = this.contacts.Where(selectContact => selectContact.PhoneNumber.Trim().ToUpper() == cmbPhoneNumber.Text.Trim().ToUpper()).FirstOrDefault();
                    if (bspContactVM != null)
                    {
                        bspVM.Id             = bspContactVM.BusinessPartnerId;
                        bspVM.mpt_StatusEnum = (int)BusinessPartnerStatusEnum.Active;
                        bspAddressVM.Id      = this.selectedBSP.addresses.FirstOrDefault().Id;
                    }
                    else
                    {
                        bspContactVM             = new BusinessPartnerContactDetails();
                        bspAddressVM             = new BusinessPartnerAddressDetails();
                        bspContactVM.Id          = 0;
                        bspContactVM.PhoneNumber = cmbPhoneNumber.Text;
                        bspContactVM.Email       = "";
                        bspAddressVM.Id          = 0;
                    }
                    bspVM.Name           = txtName.Text;
                    bspAddressVM.Address = txtAddress.Text;

                    bspVM.contacts  = bspVM.contacts.Append(bspContactVM);
                    bspVM.addresses = bspVM.addresses.Append(bspAddressVM);

                    using (ReceiptBLL receipt = new ReceiptBLL())
                    {
                        BusinessPartnerResponse bspResponse = receipt.ManageBusinessPartner(bspVM);
                        bspVM.Id = bspResponse.BusinessPartnerId;

                        bspContactVM = (from contact in bspVM.contacts
                                        select contact).FirstOrDefault();

                        bspAddressVM = (from address in bspVM.addresses
                                        select address).FirstOrDefault();
                        bspContactVM.BusinessPartnerId = bspResponse.BusinessPartnerId;
                        bspContactVM.Id = bspResponse.ContactId;
                        bspAddressVM.BusinessPartnerId = bspResponse.BusinessPartnerId;
                        bspAddressVM.Id = bspResponse.AddressId;

                        this.selectedBSP = bspVM;
                        this.setBspLables(this.selectedBSP);
                        this.btnCustomerAdd.Enabled   = false;
                        this.btnCustomerReset.Enabled = false;
                    }
                }
                else
                {
                    MessageBox.Show("Mandatory fields are missing");
                }
            }
            else
            {
                this.setBspLables(this.selectedBSP);
            }
        }
 protected void LinqDataSourceFind_Selecting(object sender, LinqDataSourceSelectEventArgs e)
 {
     e.Result = ReceiptBLL.Find(txtNameFind.Text.Trim());
 }