private void btnAdd_Click(object sender, EventArgs e) { string err = DataValidate(); if (!string.IsNullOrEmpty(err)) { MessageBox.Show(err, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (mode == "NEW" && dupadhar) { string msg = "This Adhar No is Already Registered with " + dupadharemp + Environment.NewLine + " Are you sure to Insert this as New Employee ?"; DialogResult qdr = MessageBox.Show(msg, "Question", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (qdr == DialogResult.No) { return; } } Cursor.Current = Cursors.WaitCursor; GrpMain.Enabled = false; using (SqlConnection cn = new SqlConnection(Utils.Helper.constr)) { using (SqlCommand cmd = new SqlCommand()) { try { if (string.IsNullOrEmpty(txtBasic.Text.Trim())) { txtBasic.Text = "0"; } if (string.IsNullOrEmpty(txtBAAll.Text.Trim())) { txtBAAll.Text = "0"; } if (string.IsNullOrEmpty(txtSplALL.Text.Trim())) { txtSplALL.Text = "0"; } cn.Open(); cmd.Connection = cn; string sql = "Insert into MastEmp (CompCode,WrkGrp,EmpUnqID,EmpName,FatherName," + " UnitCode,MessCode,MessGrpCode,BirthDt,JoinDt,ValidFrom,ValidTo," + " ADHARNO,IDPRF3,IDPRF3No,Sex,ContractFlg,PayrollFlg,OTFLG,Weekoff,Active,AddDt,AddID,Basic,ValidityExpired,SPLALL,BAALL,PunchingBlocked) Values (" + "'{0}','{1}','{2}','{3}','{4}' ," + " '{5}',{6},{7},'{8}','{9}',{10},{11}," + " '{12}','ADHARCARD','{13}','{14}','{15}','{16}','{17}','{18}','1',GetDate(),'{19}','{20}','{21}','{22}','{23}','{24}')"; sql = string.Format(sql, txtCompCode.Text.Trim().ToString(), txtWrkGrpCode.Text.Trim().ToString(), txtEmpUnqID.Text.Trim().ToString(), txtEmpName.Text.Trim().ToString(), txtFatherName.Text.Trim(), txtUnitCode.Text.ToString(), ((txtMessCode.Text.Trim() == "")? "null" :"'" + txtMessCode.Text.Trim() + "'"), ((txtMessGrpCode.Text.Trim() == "")? "null" :"'" + txtMessGrpCode.Text.Trim() + "'"), txtBirthDT.DateTime.ToString("yyyy-MM-dd"), txtJoinDt.DateTime.ToString("yyyy-MM-dd"), ((txtWrkGrpCode.Text.Trim() == "COMP") ? "null" : "'" + txtValidFrom.DateTime.ToString("yyyy-MM-dd") + "'"), ((txtWrkGrpCode.Text.Trim() == "COMP") ? "null" : "'" + txtValidTo.DateTime.ToString("yyyy-MM-dd") + "'"), txtAdharNo.Text.Trim(), txtAdharNo.Text.Trim(), ((Convert.ToBoolean(txtGender.EditValue))?1:0), ((chkCont.Checked)?1:0), ((chkComp.Checked)?1:0), ((chkOTFlg.Checked)?1:0), txtWeekOff.Text.Trim(), Utils.User.GUserID, txtBasic.Text.Trim().ToString(), "0", txtSplALL.Text.Trim().ToString(), txtBAAll.Text.Trim().ToString(), "0" ); cmd.CommandText = sql; cmd.ExecuteNonQuery(); //createmuster clsEmp t = new clsEmp(); string err2 = string.Empty; if (t.GetEmpDetails(txtCompCode.Text.Trim(), txtEmpUnqID.Text.Trim())) { DateTime sFromDt, sToDt, sCurDt; sCurDt = Convert.ToDateTime(Utils.Helper.GetDescription("Select GetDate()", Utils.Helper.constr)); if (txtJoinDt.DateTime.Year < sCurDt.Year) { sFromDt = Convert.ToDateTime(Utils.Helper.GetDescription("Select CalendarStartOfYearDate from dbo.F_TABLE_DATE(GetDate(),GetDate())", Utils.Helper.constr)); sToDt = Convert.ToDateTime(Utils.Helper.GetDescription("Select CalendarEndOfYearDate from dbo.F_TABLE_DATE(GetDate(),GetDate())", Utils.Helper.constr)); } else { sFromDt = txtJoinDt.DateTime; sToDt = Convert.ToDateTime(Utils.Helper.GetDescription("Select CalendarEndOfYearDate from dbo.F_TABLE_DATE('" + sFromDt.ToString("yyyy-MM-dd") + "','" + sFromDt.ToString("yyyy-MM-dd") + "')", Utils.Helper.constr)); } if (!t.CreateMuster(sFromDt, sToDt, out err2)) { MessageBox.Show(err, "Error While Creating Muster Table", MessageBoxButtons.OK, MessageBoxIcon.Error); } } if (string.IsNullOrEmpty(err2)) { MessageBox.Show("Record saved...", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show("Record saved with error please check muster table created...", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information); } ResetCtrl(); }catch (Exception ex) { MessageBox.Show(ex.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } GrpMain.Enabled = true; Cursor.Current = Cursors.Default; }