Exemple #1
0
        public void UpdateRecord(Objects.ProfitDistribution obj)
        {
            try
            {
                SqlCommand cmd = new SqlCommand();
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.CommandText = "SP_ProfitDistributionUpdate";

                cmd.Parameters.AddWithValue("@DistributionID", obj.DistributionID);
                cmd.Parameters.AddWithValue("@DistributionDate", obj.DistributionDate);
                cmd.Parameters.AddWithValue("@SchemeID", obj.SchemeID);
                cmd.Parameters.AddWithValue("@NetProfit", obj.NetProfit);
                cmd.Parameters.AddWithValue("@Remarks", obj.Remarks);
                cmd.Parameters.AddWithValue("@UserID", obj.UserID);

                new Database(connectionstring).ExecuteNonQueryOnly(cmd);
            }
            catch (Exception exc)
            {
                throw exc;
            }
        }
Exemple #2
0
        public DataTable InsertRecord(Objects.ProfitDistribution obj)
        {
            try
            {
                SqlCommand cmd = new SqlCommand();
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.CommandText = "SP_ProfitDistributionInsert";

                cmd.Parameters.AddWithValue("@DistributionDate", obj.DistributionDate);
                cmd.Parameters.AddWithValue("@SchemeID", obj.SchemeID);
                cmd.Parameters.AddWithValue("@NetProfit", obj.NetProfit);
                cmd.Parameters.AddWithValue("@Remarks", obj.Remarks);
                cmd.Parameters.AddWithValue("@UserID", obj.UserID);

                DataTable dt = new Database(connectionstring).ExecuteForDataTable(cmd);
                return(dt);
            }
            catch (Exception exc)
            {
                throw exc;
            }
        }
        private void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                decimal vTotalAmount, vNetProfit = 0;
                decimal.TryParse(txtTotalAmount.Text, out vTotalAmount);
                decimal.TryParse(txtNetProfit.Text, out vNetProfit);

                bool vHasSelectedRows = false;

                foreach (DataGridViewRow dr in Grid.Rows)
                {
                    if (Convert.ToBoolean(dr.Cells["Select"].Value) == true)
                    {
                        vHasSelectedRows = true;
                        break;
                    }
                }


                if (!vHasSelectedRows)
                {
                    MessageBox.Show("Please Select a Member to Save..", "Detail Missing");
                    Grid.Focus();
                    return;
                }

                Objects.ProfitDistribution BAL = new Objects.ProfitDistribution();
                BAL.DistributionID   = int.Parse(txtDistID.Text);
                BAL.DistributionDate = dt_Entry.Value;
                BAL.SchemeID         = int.Parse(cboScheme.SelectedValue.ToString());
                BAL.NetProfit        = decimal.Parse(txtNetProfit.Text);
                BAL.Remarks          = txtRemarks.Text;
                BAL.UserID           = vUserID;

                if (vOpenMode)
                {
                    objDAL.UpdateRecord(BAL);
                    objDAL.DeleteRecordBody(int.Parse(txtDistID.Text));
                }
                else
                {
                    DataTable dt = objDAL.InsertRecord(BAL);
                    BAL.DistributionID = int.Parse(dt.Rows[0]["DistributionID"].ToString());
                }

                //Save Detail
                foreach (DataGridViewRow dr in Grid.Rows)
                {
                    if (dr.Cells[0].Value != null && Convert.ToBoolean(dr.Cells["Select"].Value) == true)
                    {
                        Objects.ProfitDistDetail objBody = new Objects.ProfitDistDetail();
                        objBody.DistributionID = BAL.DistributionID;
                        objBody.MemberID       = Int64.Parse(dr.Cells["MemberID"].Value.ToString());
                        objBody.ProfitRate     = decimal.Parse(dr.Cells["Rate"].Value.ToString());
                        objBody.ProfitAmount   = decimal.Parse(dr.Cells["Amount"].Value.ToString());

                        objDAL.InsertRecordBody(objBody);
                    }
                }

                Message.ShowMessage(MyMessages.MessageType.SaveRecord);
                ClearFields();
            }
            catch (Exception exc)
            {
                MessageBox.Show(exc.Message.ToString(), "Error");
            }
        }