コード例 #1
0
        public void InsertRecordBody(Objects.SaleBody obj)
        {
            try
            {
                SqlCommand cmd = new SqlCommand();
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.CommandText = "SP_SaleBodyInsert";

                cmd.Parameters.AddWithValue("@SaleID", obj.SaleID);
                cmd.Parameters.AddWithValue("@ProductID", obj.ProductID);
                cmd.Parameters.AddWithValue("@Qty", obj.Qty);
                cmd.Parameters.AddWithValue("@Price", obj.Price);
                cmd.Parameters.AddWithValue("@Discount", obj.Discount);
                cmd.Parameters.AddWithValue("@TotalValue", obj.TotalValue);
                cmd.Parameters.AddWithValue("@Cost", obj.Cost);
                cmd.Parameters.AddWithValue("@Remarks", obj.Remarks);

                new Database(connectionstring).ExecuteNonQueryOnly(cmd);
            }
            catch (Exception exc)
            {
                throw exc;
            }
        }
コード例 #2
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                if (string.IsNullOrEmpty(txtCustomerID.Text.Trim()))
                {
                    MessageBox.Show("Please Insert/Select Customer", "Information Missing");
                    txtCustomerID.Focus();
                    return;
                }

                if (Grid.Rows.Count == 0)
                {
                    MessageBox.Show("Please Insert Products Information", "Detail Missing");
                    txt_ProductID.Focus();
                    return;
                }

                decimal vCashPaid = 0;
                decimal.TryParse(txtCashPaid.Text, out vCashPaid);

                decimal vSpecDisc = 0;
                decimal.TryParse(txtSpecialDisc.Text, out vSpecDisc);

                Objects.Sale BAL = new Objects.Sale();

                BAL.SaleID       = Int64.Parse(txt_InvNo.Text);
                BAL.EntryDate    = dt_Entry.Value;
                BAL.CustomerID   = int.Parse(txtCustomerID.Text);
                BAL.GrossValue   = decimal.Parse(txt_Gross.Text);
                BAL.CashReceived = vCashPaid;
                BAL.SpecialDisc  = vSpecDisc;
                BAL.Narration    = txt_Narration.Text;
                BAL.UserID       = vUserID;
                BAL.SalesmanID   = Int32.Parse(cboSalesman.SelectedValue.ToString());

                if (vOpenMode)
                {
                    objDAL.UpdateRecord(BAL);
                    objDAL.DeleteRecordBody(Int64.Parse(txt_InvNo.Text));
                }
                else
                {
                    BAL.SaleID = objDAL.getNextNo();
                    objDAL.InsertRecord(BAL);
                }

                //Save Detail
                foreach (DataGridViewRow dr in Grid.Rows)
                {
                    if (dr.Cells[0].Value != null)
                    {
                        Objects.SaleBody objBody = new Objects.SaleBody();
                        objBody.SaleID     = Int64.Parse(txt_InvNo.Text);
                        objBody.ProductID  = Int64.Parse(dr.Cells["ProductID"].Value.ToString());
                        objBody.Qty        = decimal.Parse(dr.Cells["Qty"].Value.ToString(), System.Globalization.NumberStyles.AllowDecimalPoint);
                        objBody.Price      = decimal.Parse(dr.Cells["Price"].Value.ToString(), System.Globalization.NumberStyles.AllowDecimalPoint);
                        objBody.Discount   = decimal.Parse(dr.Cells["Disc"].Value.ToString(), System.Globalization.NumberStyles.AllowDecimalPoint);
                        objBody.TotalValue = decimal.Parse(dr.Cells["TotalValue"].Value.ToString(), System.Globalization.NumberStyles.AllowDecimalPoint);
                        objBody.Cost       = decimal.Parse(dr.Cells["Cost"].Value.ToString(), System.Globalization.NumberStyles.AllowDecimalPoint);
                        objBody.Remarks    = dr.Cells["Remarks"].Value.ToString();

                        objDAL.InsertRecordBody(objBody);
                    }
                }

                MessageBox.Show("Record Saved Successfully.", "Task Completed");
                SetMode(false);
            }
            catch (Exception exc)
            {
                MessageBox.Show(exc.Message.ToString(), "Error");
            }
        }