Esempio n. 1
0
        public IList<SaleDetail> getsaleDetailByCode(string _saleCode)
        {
            IList<SaleDetail> saleDetails = new List<SaleDetail>();
            SaleDetail saleDetail = null;

            try
            {
                Conn = db.openConnAccess();
                sb = new StringBuilder();

                sb.Remove(0, sb.Length);
                sb.Append(" SELECT ID,SaleCode,PCode,PName,UCode,UName,Amount,SalePrice,NetTotal FROM tbSaleDetail ");
                sb.Append(" WHERE (SaleCode='" + _saleCode + "')");
                string sql;
                sql = sb.ToString();

                com = new OleDbCommand();
                com.CommandText = sql;
                com.CommandType = CommandType.Text;
                com.Connection = Conn;
                dr = com.ExecuteReader();
                if (dr.HasRows)
                {

                    DataTable dt = new DataTable();
                    dt.Load(dr);
                    int index = 1;
                    foreach (DataRow drw in dt.Rows)
                    {
                        saleDetail = new SaleDetail();
                        saleDetail.ID = Convert.ToInt32(drw["ID"].ToString());
                        saleDetail.Index = Convert.ToString(index);
                        saleDetail.SaleCode = drw["SaleCode"].ToString();
                        saleDetail.PCode= drw["PCode"].ToString();
                        saleDetail.PName = drw["PName"].ToString();
                        saleDetail.UCode = drw["UCode"].ToString();
                        saleDetail.UName = drw["UName"].ToString();
                        saleDetail.Amount =Convert.ToInt32(drw["Amount"].ToString());
                        saleDetail.SalePrice =Convert.ToDouble(drw["SalePrice"].ToString());
                        saleDetail.NetTotal= Convert.ToDouble(drw["NetTotal"].ToString());
                        saleDetails.Add(saleDetail);

                    }

                }

                dr.Close();

            }
            catch (Exception ex)
            {
                dr.Close();
                Conn.Close();
                return null;
                throw ex;

            }
            finally
            {
                Conn.Close();
            }

            return saleDetails;
        }
Esempio n. 2
0
        private void cmdSave_Click(object sender, EventArgs e)
        {
            if (txtSearchCustomer.Text.Trim() == "")
            {
                MessageBox.Show("กรุณากรอกชื่อลูกค้าด้วย !!!", "ผลการตรวจสอบ", MessageBoxButtons.OK, MessageBoxIcon.Information);
                txtSearchCustomer.Focus();
                return;
            }

            int count = lsvProductList.Items.Count;
            if (count == 0)
            {
                MessageBox.Show("กรุณาเลือกสินค้าด้วย !!!", "ผลการตรวจสอบ", MessageBoxButtons.OK, MessageBoxIcon.Information);
                txtSearchProduct.Focus();
                return;

            }

            if (MessageBox.Show("คุณต้องการขายสินค้า ใช่หรือไม่?", "คำยืนยัน", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.Yes)
            {

                try
                {
                    Sale sale = serviceSale.getBySaleCode(txtSaleCode.Text.Trim());
                    if (sale == null)
                    {
                        Sale newSale = new Sale();
                        newSale.SaleCode = txtSaleCode.Text.Trim();
                        Customer cus = serviceCustomer.getByCode(txtSearchCustomer.Text.Trim());
                        newSale.CustomerForSale = cus;
                        newSale.PQutation = txtQutation.Text.Trim();
                        newSale.DateSale = dtpSale.Value;
                        newSale.SaleBy = "";//รอ ทำระบบ login ก่อน
                        newSale.NetDc = Convert.ToDouble(lblNetDC.Text.Trim());
                        newSale.NetVat =Convert.ToDouble(lblNetVAT.Text.Trim());
                        newSale.NetTotal = Convert.ToDouble(lblNet.Text.Trim());

                        IList<SaleDetail> saleDetails = new List<SaleDetail>();
                        SaleDetail saleDetail = null;
                        int j = 1;
                        for (int i = 0; i <= lsvProductList.Items.Count - 1; i++)
                        {
                            saleDetail = new SaleDetail();
                            saleDetail.Index = Convert.ToString(j);
                            saleDetail.SaleCode = txtSaleCode.Text.Trim();
                            saleDetail.PCode = lsvProductList.Items[i].SubItems[0].Text.Replace(",", "");
                            saleDetail.PName = lsvProductList.Items[i].SubItems[1].Text.Replace(",", "");
                            Product product = serviceProduct.getByCode(lsvProductList.Items[i].SubItems[0].Text.Replace(",", ""));
                            saleDetail.UCode = product.UCode;
                            saleDetail.UName = product.UName;
                            saleDetail.Amount= Convert.ToInt32(lsvProductList.Items[i].SubItems[3].Text.Replace(",", ""));
                            saleDetail.SalePrice = Convert.ToDouble(lsvProductList.Items[i].SubItems[2].Text.Replace(",", ""));
                            saleDetail.NetTotal = Convert.ToDouble(lsvProductList.Items[i].SubItems[4].Text.Replace(",", ""));
                            saleDetails.Add(saleDetail);
                            j++;

                        }
                        newSale.saleDetails = saleDetails;

                        bool save = serviceSale.Save(newSale, cboWarehouse.SelectedValue.ToString());
                        if (save)
                        {
                            MessageBox.Show("เพิ่มการขายสินค้า เรียบร้อยแล้ว !!!", "ผลการทำงาน", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            ClearProduct();
                            ClearNet();
                            lsvProductList.Items.Clear();
                            txtSearchProduct.Focus();
                            ClearCustomer();

                            txtSaleCode.Text = serviceSale.getSaleCode();
                        }
                        else
                        {
                            MessageBox.Show("ไม่สามารถ เพิ่มการขายสินค้าได้!!!", "ผลการทำงาน", MessageBoxButtons.OK, MessageBoxIcon.Information);

                        }

                    }
                    else {

                        MessageBox.Show("ไม่สามารถ บันทึกการขายสินค้าได้ เนื่องจาก !!! มีหมายเลขการขายสินค้านี้แล้ว ", "ผลการทำงาน", MessageBoxButtons.OK, MessageBoxIcon.Information);

                    }

                }
                catch (Exception ex) {
                    MessageBox.Show("ไม่สามารถ บันทึกการขายสินค้าได้ เนื่องจาก !!! : " + ex.Message, "ผลการทำงาน", MessageBoxButtons.OK, MessageBoxIcon.Information);

                }

            }
        }