コード例 #1
0
        public bool insertContractDate(ContractDate contractDate)
        {
            using (System.Data.SqlClient.SqlConnection conn = new System.Data.SqlClient.SqlConnection(text))
            {
                using (System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand())
                {
                    cmd.Connection = con;
                    con.Open();

                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.CommandText = "spInsertContractDate";
                    cmd.Parameters.AddWithValue("@ContractId", contractDate.ContractID);
                    cmd.Parameters.AddWithValue("@No", contractDate.No);
                    if (contractDate.RedeemDate == null)
                    {
                        cmd.Parameters.AddWithValue("@RedeemDate", DBNull.Value);
                    }
                    else
                    {
                        cmd.Parameters.AddWithValue("@RedeemDate", contractDate.RedeemDate);
                    }
                    if (contractDate.SignDate == null)
                    {
                        cmd.Parameters.AddWithValue("@SignDate", DBNull.Value);
                    }
                    else
                    {
                        cmd.Parameters.AddWithValue("@SignDate", contractDate.SignDate);
                    }


                    IAsyncResult result = cmd.BeginExecuteNonQuery();
                    cmd.EndExecuteNonQuery(result);
                    con.Close();
                    return(result.IsCompleted);
                }
            }
        }
コード例 #2
0
 public bool InsertContractDate(ContractDate ContractDate)
 {
     return(insertContractDate(ContractDate));
 }
コード例 #3
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                bool resultContract;
                int  signCount  = 0;
                int  alertCount = 0;

                if (!validateForm())
                {
                    return;
                }

                int            ID             = _mode == "Edit" ? _id : Convert.ToInt32(obj.getLastContractID().Rows[0][0]) + 1;
                Contract       contract       = new Contract();
                ContractDate   contractDate   = new ContractDate();
                ContractAlert  contractAlert  = new ContractAlert();  //1.0.3
                ContractMember contractMember = new ContractMember();

                if (_mode == "Edit")
                {
                    obj.deleteContractDate(ID);
                    obj.deleteContractAlert(ID); //1.0.3
                    obj.deleteContractMember(ID);
                }

                //Insert Contract Date
                DataTable dtContractDate = new DataTable();
                dtContractDate = (DataTable)gridControlDate.DataSource;
                DataView dv = dtContractDate.DefaultView;
                dv.Sort        = "RedeemDate";
                dtContractDate = dv.ToTable();
                foreach (DataRow row in dtContractDate.Rows) // Loop over the rows.
                {
                    contractDate.ContractID = ID;
                    //contractDate.No = Convert.ToInt32(row["No"]);
                    contractDate.No = signCount + 1;
                    if (row["RedeemDate"].ToString().Equals(""))
                    {
                        contractDate.RedeemDate = null;
                    }
                    else
                    {
                        contractDate.RedeemDate = Convert.ToDateTime(row["RedeemDate"]);
                    }
                    if (row["SignDate"].ToString().Equals(""))
                    {
                        contractDate.SignDate = null;
                    }
                    else
                    {
                        contractDate.SignDate = Convert.ToDateTime(row["SignDate"]);
                    }
                    signCount++;
                    bool resultContractDate = obj.InsertContractDate(contractDate);
                }

                //Insert Contract Member
                DataTable dtContractMember = new DataTable();
                dtContractMember = (DataTable)gridControlMember.DataSource;
                foreach (DataRow row in dtContractMember.Rows) // Loop over the rows.
                {
                    contractMember.ContractID = ID;
                    contractMember.MemberID   = Convert.ToInt32(row["MemberId"]);
                    contractMember.Value      = Convert.ToDecimal(row["Value"]);
                    bool resultContractMember = obj.InsertContractMember(contractMember);
                }

                //1.0.3
                //Insert Contract Alert
                DataTable dtContractAlert = new DataTable();
                dtContractAlert = (DataTable)gridControlAlert.DataSource;
                DataView dv2 = dtContractAlert.DefaultView;
                dv2.Sort        = "AlertDate";
                dtContractAlert = dv2.ToTable();
                foreach (DataRow row in dtContractAlert.Rows) // Loop over the rows.
                {
                    contractAlert.ContractID = ID;
                    //contractDate.No = Convert.ToInt32(row["No"]);
                    contractAlert.No        = alertCount + 1;
                    contractAlert.AlertType = row["AlertType"].ToString();

                    if (row["AlertDate"].ToString().Equals(""))
                    {
                        contractAlert.AlertDate = null;
                    }
                    else
                    {
                        contractAlert.AlertDate = Convert.ToDateTime(row["AlertDate"]);
                    }
                    alertCount++;
                    bool resultContractDate = obj.InsertContractAlert(contractAlert);
                }

                if (_mode == "Edit")
                {
                    //Update Contract
                    contract.ContractID    = ID;
                    contract.Title         = cboAssetType.Text.ToString() + " " + txtTitle.Text.ToString();
                    contract.StatusID      = Convert.ToInt32(rdStatus1.Checked ? 1 : 2);
                    contract.ContracTypeID = Convert.ToInt32(cboContractType.SelectedValue);
                    contract.TotalValue    = Convert.ToDecimal(txtValue.Text);
                    contract.ContractDate  = ((dtpContractDate.Value != DateTime.MinValue) ? (DateTime?)dtpContractDate.Value : null);
                    contract.SignCount     = signCount;
                    resultContract         = obj.UpdateContract(contract);

                    if (resultContract)
                    {
                        obj.dbFullBackUp();
                        this.Close();
                        MessageBox.Show("แก้ไขเรียบร้อย", "ผลการบันทึก", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        //System.Diagnostics.Process.Start("Chrome.exe", "https://www.google.com/calendar/");
                    }
                    else
                    {
                        MessageBox.Show("พบข้อบกพร่อง ไม่สามารถแก้ไขได้", "ผลการบันทึก", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
                else if (_mode == "New")
                {
                    //Insert Contract
                    contract.ContractID    = ID;
                    contract.Title         = cboAssetType.Text.ToString() + " " + txtTitle.Text.ToString();
                    contract.StatusID      = Convert.ToInt32(rdStatus1.Checked ? 1 : 2);
                    contract.ContracTypeID = Convert.ToInt32(cboContractType.SelectedValue);
                    contract.TotalValue    = Convert.ToDecimal(txtValue.Text);
                    contract.ContractDate  = ((dtpContractDate.Value != DateTime.MinValue) ? (DateTime?)dtpContractDate.Value : null);
                    contract.SignCount     = signCount;
                    resultContract         = obj.InsertContract(contract);

                    if (resultContract)
                    {
                        obj.dbFullBackUp();
                        this.Close();
                        MessageBox.Show("บันทึกเรียบร้อย", "ผลการบันทึก", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        //System.Diagnostics.Process.Start("Chrome.exe", "https://www.google.com/calendar/");
                    }
                    else
                    {
                        MessageBox.Show("พบข้อบกพร่อง ไม่สามารถบันทึกได้", "ผลการบันทึก", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("โปรแกรมพบข้อผิดพลาด", "พบข้อผิดพลาด", MessageBoxButtons.OK, MessageBoxIcon.Error);
                Log.LogWrite(DateTime.Now.ToString() + "\r\n" + ex.ToString());
                Application.Exit();
            }
        }