Пример #1
0
        private void button1_Click(object sender, EventArgs e)
        {
            if(textBox1.Text == "" || tbNewPassword.Text =="" || tbConfirmPassword.Text =="" || tbNewPassword.Text != tbConfirmPassword.Text)
            {
                MessageBox.Show("Please input field! Verify New Password and Confirm Password is the same!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            else
            {
                try
                {
                    Entities1 mdl = new Entities1();
                    mdl.Connection.Open();
                    user user = new user();
                    user.user_name = textBox1.Text;
                    user.user_password = tbNewPassword.Text;
                    user.created_by = Global.GlobalVar;
                    user.created_date = DateTime.Now;
                    user.updated_by = Global.GlobalVar;
                    user.updated_date = DateTime.Now;
                    user.user_address = "";
                    user.user_birth_date = DateTime.Now;
                    user.user_birth_place = "";
                    user.user_email = "";
                    user.user_first_name = "";
                    user.user_last_name = "";
                    user.user_last_login = DateTime.Parse("01/01/1970");
                    user.user_phone_number = "";
                    user.user_photo_file = "";
                    user.user_social_number = "";
                    user.user_marital_status = "";
                    user.user_gender = "";
                    user.user_group_id = 1;
                    mdl.AddTousers(user);
                    mdl.SaveChanges();
                    mdl.Connection.Close();

                    MessageBox.Show("Success Add New User", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    Loading();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message + " " + ex.InnerException + " " + ex.StackTrace, "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
            }
        }
 private void button1_Click(object sender, EventArgs e)
 {
     if (tbOldPassword.Text.Trim() == "" ||  tbNewPassword.Text.Trim() == "" || tbConfirmPassword.Text.Trim()=="" || tbConfirmPassword.Text != tbNewPassword.Text)
     {
         MessageBox.Show("Please input field! Verify New Password and Confirm Password is the same!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
         tbOldPassword.Text = "";
         tbNewPassword.Text = "";
         tbConfirmPassword.Text = "";
         tbOldPassword.Focus();
     }
     else
     {
         Entities1 mdl = new Entities1();
         mdl.Connection.Open();
         using (MD5 md5Hash = MD5.Create())
         {
             string hash = this.GetMd5Hash(md5Hash, tbOldPassword.Text);
             string hash2 = this.GetMd5Hash(md5Hash, tbNewPassword.Text);
             user login = mdl.sp_login_user(textBox1.Text, hash).FirstOrDefault();
             if (login != null)
             {
                 user access = (from c in mdl.users
                                where c.user_name == textBox1.Text
                                select c).FirstOrDefault();
                 access.user_password = hash2;
                 mdl.SaveChanges();
                 MessageBox.Show("Success Change Password", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
                 this.Close();
             }
             else
             {
                 MessageBox.Show("Username or Old Password Error", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                 tbOldPassword.Text = "";
                 tbNewPassword.Text = "";
                 tbConfirmPassword.Text = "";
                 tbOldPassword.Focus();
             }
         }
         mdl.Connection.Close();
     }
 }
        private void btnSaveData_Click(object sender, EventArgs e)
        {
            Boolean error = false;
            try
            {
                /* SAVE BANK DATA */
                foreach (t_Bank_data bankObj in bankList)
                {

                    Entities1 mdl = new Entities1();
                    mdl.Connection.Open();
                    t_Bank_data selectBank = new t_Bank_data();
                    selectBank = (from c in mdl.t_Bank_data
                                  where (c.policy_no == bankObj.policy_no)
                                  select c).FirstOrDefault();

                    /*IF NOT EXIST, DO INSERT*/
                    if (selectBank == null)
                    {

                        mdl.AddTot_Bank_data(bankObj);
                        mdl.SaveChanges();
                        mdl.Connection.Close();
                    }
                }

                t_Insurance_data temp = new t_Insurance_data();
                /* SAVE INSURANCE DATA */
                foreach (t_Insurance_data insObj in insList)
                {

                    Entities1 mdl = new Entities1();
                    mdl.Connection.Open();
                    t_Insurance_data selectIns = new t_Insurance_data();
                    selectIns = (from c in mdl.t_Insurance_data
                                 where (c.policy_no == insObj.policy_no)&& (c.ic_breg_no == insObj.ic_breg_no)
                                 select c).FirstOrDefault();

                    /*IF NOT EXIST, DO INSERT*/
                    if (selectIns == null)
                    {
                        temp=insObj;
                        mdl.AddTot_Insurance_data(temp);
                        mdl.SaveChanges();
                        mdl.Connection.Close();
                    }
                }

                /*SAVE DMMS*/
                foreach(t_dmms_master mergeObj in mrgList)
                {
                    Entities1 mdl = new Entities1();
                    mdl.Connection.Open();
            //                    mergeObj.SETTLEMENT_DATE = Convert.ToDateTime("01/01/1970");
            //                    mergeObj.ADD_NEW_CUSTOMER_DATE = Convert.ToDateTime("01/01/1970");
                    mdl.AddTot_dmms_master(mergeObj);
                    mdl.SaveChanges();
                    mdl.Connection.Close();

                }

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + " Inner Exception : " + ex.InnerException + " " + ex.Source + ex.StackTrace);
                error = true;
                btnFinish_4.Enabled = false;
                btnSaveData.Enabled = true;
            }
            if (error == false)
            {
                MessageBox.Show("Save Success");
                btnFinish_4.Enabled = true;
                btnSaveData.Enabled = false;
            }
        }