コード例 #1
0
        private void cmdSave_Click(object sender, EventArgs e)
        {
            if (txtpsnCode.Text.Trim() == "")
            {
                MessageBox.Show("กรุณาเลือกพนักงานก่อน !!!", "ผลการตรวจสอบ", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                txtpsnCode.Focus();
                return;
            }

            if (txtinsurance.Text.Trim() == "")
            {
                MessageBox.Show("กรุณาป้อนเงินประกันก่อน !!!", "ผลการตรวจสอบ", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                txtinsurance.Focus();
                return;
            }

            Insurance newInsurance = new Insurance();
            Person p = new Person();
            p = personService.getPersonBypsnCode(txtpsnCode.Text.Trim());
            newInsurance.person = p;

            InsuranceDetail insuranceDetail = new InsuranceDetail();
            insuranceDetail.insurance = newInsurance;

            string _date = String.Format("{0:dd/MM/yyyy}", DateTime.Now);
            insuranceDetail.indate = _date;
            insuranceDetail.amount =Convert.ToInt32(txtinsurance.Text.Trim());

            List<InsuranceDetail> insuranceDetails = new List<InsuranceDetail>();
            insuranceDetails.Add(insuranceDetail);

            newInsurance.insuranceDetails = insuranceDetails;

            int result = 0;
            Insurance insuranceOld = insuranceService.getInsuranceBypsnCode(txtpsnCode.Text.Trim());
            if (insuranceOld == null)
            {
                result = insuranceService.CreateInsurance(newInsurance);
            }
            else {
                result = insuranceService.UpdateInsurance(insuranceOld,Convert.ToInt32(txtinsurance.Text.Trim()));
            }

            if (result > -1)
            {
                Console.WriteLine("Insert Complete");
                lblresult.Visible = true;
                lblresult.Text = " บันทึกเรียบร้อย ";
            }
            else {
                Console.WriteLine("Insert Not Complete");
                lblresult.Visible = true;
                lblresult.Text = " ไม่สามารถบันทึกข้อมูลได้";

            }
        }
コード例 #2
0
        public List<InsuranceDetail> getInsuranceDetailByinID(string _inID)
        {
            InsuranceDetail insuranceDetail = null;
            List<InsuranceDetail> insuranceDetails = new List<InsuranceDetail>();

            try
            {
                conn = db.openConn();
                sb = new StringBuilder();

                sb.Remove(0, sb.Length);
                sb.Append(" SELECT ID,INID,inDate,amount FROM tbInsurDetail ");
                sb.Append(" WHERE INID='"+_inID+"'");
                string sql;
                sql = sb.ToString();

                comm = new SqlCommand();
                comm.CommandText = sql;
                comm.CommandType = CommandType.Text;
                comm.Connection = conn;
                dr = comm.ExecuteReader();
                if (dr.HasRows)
                {
                    DataTable dt = new DataTable();
                    dt.Load(dr);
                    foreach (DataRow drw in dt.Rows)
                    {
                        insuranceDetail = new InsuranceDetail();
                        insuranceDetail.ID = Convert.ToInt32(drw["ID"].ToString());
                        Insurance insurance = new Insurance();
                        insurance.ID  = drw["INID"].ToString();
                        insuranceDetail.indate =(drw["inDate"].ToString());
                        insuranceDetail.amount = Convert.ToInt32(drw["amount"].ToString());
                        insuranceDetails.Add(insuranceDetail);
                    }

                }

                dr.Close();

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

            }
            finally
            {
                conn.Close();
            }
            return insuranceDetails;
        }