protected void ChangePassword_ServerClick(object sender, EventArgs e) { Telerik.Web.UI.RadWindowManager windowManager = new Telerik.Web.UI.RadWindowManager(); Telerik.Web.UI.RadWindow widnow1 = new Telerik.Web.UI.RadWindow(); // Set the window properties widnow1.NavigateUrl = "~/CommonUI/ChangeTeacherPassword.aspx"; widnow1.ID = "RadWindow1"; widnow1.VisibleOnPageLoad = true; // Set this property to True for showing window from code windowManager.Windows.Add(widnow1); this.form1.Controls.Add(widnow1); }
public override void InitializeCell(DataControlFieldCell cell, DataControlCellType cellType, DataControlRowState rowState, int rowIndex) { string s = ItemTemplate.ToString(); switch (cellType) { case DataControlCellType.DataCell: System.Web.UI.Control c = new System.Web.UI.Control(); ItemTemplate.InstantiateIn(c); cell.Controls.Add(c); EditWindow = new RadWindow(); EditWindow.Modal = true; EditWindow.VisibleStatusbar = false; EditWindow.Height = 350; EditWindow.Width = 490; EditWindow.DestroyOnClose = false; EditWindow.Title = "Edit Performance Indicator Metrics"; cell.Controls.Add(EditWindow); Control.PreRender += new EventHandler(Control_PreRender); break; case DataControlCellType.Header: if (!string.IsNullOrEmpty(HeaderText)) { cell.Controls.Add(new LiteralControl(HeaderText + "<br>")); } EditLink = new HyperLink(); EditLink.Text = "Edit"; cell.Controls.Add(EditLink); break; } }
protected void btn_import_Click(object sender, EventArgs e) { try { string strcon = null; string strfilename1 = fu_masters.FileName; strfilename2 = Convert.ToString(DateTime.Now.TimeOfDay) + "_" + strfilename1; strfilename2 = strfilename2.Replace("/", "").Replace(":", "."); if (fu_masters.HasFile) { if (System.IO.Directory.Exists(Server.MapPath("~/IMPORT_EXCEL/")) == false) { System.IO.Directory.CreateDirectory(Server.MapPath("~/IMPORT_EXCEL/")); } fu_masters.PostedFile.SaveAs(System.IO.Path.Combine(Server.MapPath("~/IMPORT_EXCEL/"), strfilename2)); string filename1 = Server.MapPath("~/IMPORT_EXCEL/") + ("") + (Convert.ToString(strfilename2)); FileInfo fileInfo = new FileInfo(filename1); if (fileInfo.Exists) { string path = MapPath(strfilename1); // string name = Path.GetFileName( path ); string ext = Path.GetExtension(path); string type = string.Empty; // set known types based on file extension if (ext != null) { switch (ext.ToLower()) { case ".xls": type = "excel"; break; case ".xlsx": type = "excel"; break; default: type = string.Empty; break; } } if (type == string.Empty) { if (System.IO.Directory.Exists(Server.MapPath("~/IMPORT_EXCEL/")) == true) { string path1 = Server.MapPath("~/IMPORT_EXCEL/") + ("") + (Convert.ToString(strfilename2)); System.IO.File.Delete(path1); } BLL.ShowMessage(this, "Please select the Excel File (Eg: Excel.xlsx). "); return; } } } else { BLL.ShowMessage(this, "Please Select the File to be uploaded"); return; } string strpath = Server.MapPath("~/IMPORT_EXCEL/"); strpath = strpath + strfilename2; // Getting data from excell file to dataset. strcon = "Provider=Microsoft.ACE.OLEDB.12.0;" + "Data Source='" + strpath + "';" + "Extended Properties=Excel 12.0;"; OleDbConnection objConn = null; objConn = new OleDbConnection(strcon); objConn.Open(); DataTable dt_chk2 = objConn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null); string sheetname; if (dt_chk2 == null) { objConn.Close(); Delete_Excel_File(); BLL.ShowMessage(this, "Please select the Correct Excel Template Sheet."); return; } else { sheetname = Convert.ToString(dt_chk2.Rows[0]["TABLE_NAME"]); } OleDbDataAdapter da = new OleDbDataAdapter("SELECT * FROM [" + sheetname + "]", strcon); da.Fill(ds); objConn.Close(); DataTable dt = new DataTable(); DataTable dtfail = new DataTable(); string errormsg = string.Empty; string projecttype = null; Int32 rowno = 0; string columnno = null; Boolean filestatus = true; dtfail.Columns.Add("S.NO", typeof(Int32)); dtfail.Columns.Add("ROWNO", typeof(Int32)); dtfail.Columns.Add("COLUMNS NAMES", typeof(string)); if (!(ds.Tables[0].Columns[0].ToString().Trim() == "Name*")) { Delete_Excel_File(); BLL.ShowMessage(this, "Please select the Correct Excel Template Sheet."); return; } if (!(ds.Tables[0].Columns[1].ToString().Trim() == "Description")) { Delete_Excel_File(); BLL.ShowMessage(this, "Please select the Correct Excel Template Sheet."); return; } if (!(ds.Tables[0].Columns[2].ToString().Trim() == "Error Message")) { Delete_Excel_File(); BLL.ShowMessage(this, "Please select the Correct Excel Template Sheet."); return; } if (ds.Tables[0].Rows.Count == 0) { Delete_Excel_File(); BLL.ShowMessage(this, "Successfully processed Excel file. No Records are Imported."); return; } for (int i = 0; i < ds.Tables[0].Rows.Count; i++) { if (ds.Tables[0].Rows[i]["Name*"].ToString().Trim() != "") { _obj_Smhr_Masters = new SMHR_MASTERS(); _obj_Smhr_Masters.MASTER_TYPE = control.ToUpper(); _obj_Smhr_Masters.MASTER_CODE = ds.Tables[0].Rows[i]["Name*"].ToString().Trim(); _obj_Smhr_Masters.ORGANISATION_ID = Convert.ToInt32(Session["ORG_ID"].ToString()); _obj_Smhr_Masters.OPERATION = operation.Check; if (Convert.ToString(BLL.get_MasterRecords(_obj_Smhr_Masters).Rows[0]["Count"]) != "0") { errormsg = lblheader.Text + " with this Name Already Exists"; filestatus = false; rowno = i + 2; columnno = "Name*"; } } else { filestatus = false; rowno = i + 2; columnno = "Name*"; } //if (!(ds.Tables[0].Rows[i]["Description"].ToString().Trim() != "")) //{ // filestatus = false; // rowno = i + 2; // columnno = columnno + "," + "Description"; //} if (filestatus == false) { DataRow newrow = dtfail.NewRow(); newrow["S.NO"] = dtfail.Rows.Count + 1; newrow["ROWNO"] = rowno; newrow["COLUMNS NAMES"] = columnno; dtfail.Rows.Add(newrow); ds.Tables[0].Rows[i]["Error Message"] = errormsg; } } if (dtfail.Rows.Count > 0) { Session["dt_fail"] = dtfail; Session["ds_data"] = ds; Delete_Excel_File(); //LinkButton lnk_Import_process = (LinkButton)RadPanelBar1.FindItemByValue("AddAttachment").FindControl("lnk_Import_process"); Telerik.Web.UI.RadWindow newwindow = new Telerik.Web.UI.RadWindow(); // RWM_POSTREPLY.Windows.Remove(newwindow); newwindow.ID = "RadWindow_import"; newwindow.NavigateUrl = "~/Payroll/frm_AttendanceImportProcess.aspx"; newwindow.Title = "Import Process"; newwindow.Width = 1150; newwindow.Height = 580; newwindow.VisibleOnPageLoad = true; if (RWM_MASTERS.Windows.Count > 1) { RWM_MASTERS.Windows.RemoveAt(1); } RWM_MASTERS.Windows.Add(newwindow); RWM_MASTERS.Visible = true; return; } else { for (int i = 0; i < ds.Tables[0].Rows.Count; i++) { _obj_Smhr_Masters = new SMHR_MASTERS(); _obj_Smhr_Masters.MASTER_TYPE = control.ToUpper(); _obj_Smhr_Masters.MASTER_CODE = ds.Tables[0].Rows[i]["Name*"].ToString().Trim(); _obj_Smhr_Masters.MASTER_DESC = ds.Tables[0].Rows[i]["Description"].ToString().Trim(); _obj_Smhr_Masters.ORGANISATION_ID = Convert.ToInt32(Session["ORG_ID"].ToString()); _obj_Smhr_Masters.ISDELETED = false; _obj_Smhr_Masters.CREATEDBY = Convert.ToInt32(Session["USER_ID"]); // ### Need to Get the Session _obj_Smhr_Masters.CREATEDDATE = DateTime.Now; _obj_Smhr_Masters.LASTMDFBY = Convert.ToInt32(Session["USER_ID"]); // ### Need to Get the Session _obj_Smhr_Masters.LASTMDFDATE = DateTime.Now; _obj_Smhr_Masters.OPERATION = operation.Insert; if (BLL.set_Master(_obj_Smhr_Masters)) { BLL.ShowMessage(this, " Successfully processed Excel file."); } } rm_MR_Page.SelectedIndex = 0; LoadGrid(); RG_Master.DataBind(); } } catch (Exception ex) { SMHR.BLL.Error_Log(Session["USER_ID"].ToString(), ex.TargetSite.ToString(), ex.Message.Replace("'", "''"), "frm_Master", ex.StackTrace, DateTime.Now); Response.Redirect("~/Frm_ErrorPage.aspx"); } }
protected void RadToolBar1_ButtonClick(object sender, Telerik.Web.UI.RadToolBarEventArgs e) { if (e.Item.Value == "ExternalStatus") { string selectedmasterSets = ""; foreach (GridDataItem item in RadGrid1.SelectedItems) { string s = item["MasterCopySeparationSet"].Text.ToString(); int n = 0; Int32.TryParse(s, out n); if (n > 0) { if (selectedmasterSets != "") { selectedmasterSets += ","; } selectedmasterSets += s; } } if (selectedmasterSets != "") { Telerik.Web.UI.RadWindow mywindow = GetRadWindow("radWindowExternalStatus"); mywindow.Title = Global.rm.GetString("txtSetExternalStatus"); mywindow.NavigateUrl = "SetExternalStatus.aspx?MasterCopySeparationSetList=" + selectedmasterSets; mywindow.VisibleOnPageLoad = true;; } } /* if (e.Item.Value == "Reimage") * { * CCDBaccess db = new CCDBaccess(); * * string errmsg = ""; * foreach (DataGridItem dataItem in DataGrid1.Items) * { * CheckBox cb = (CheckBox)dataItem.Cells[0].Controls[1]; * if (cb.Checked) * { * if ((bool)Session["SelectedAllSeps"] == false) * { * try * { * // All page colors * TableCell cell = dataItem.Cells[(int)ViewState["MasterSetColumn"]]; * db.ReimageFlatSeparation(Int32.Parse(cell.Text), -1, "", out errmsg); * } * catch * { } * } * else * { * try * { * // Specific color separation * TableCell cell = dataItem.Cells[(int)ViewState["MasterSetColumn"]]; * TableCell cell2 = dataItem.Cells[(int)ViewState["ColorColumn"]]; * db.ReimageFlatSeparation(Int32.Parse(cell.Text), -1, cell2.Text, out errmsg); * } * catch * { } * } * } * } * * * } * // if (e.Item.Value == "Refresh" || e.Item.Value == "HideFinished" || e.Item.Value == "Separations") * // { * ReBind(); * //} */ ReBind(); }
protected void btn_Import_Click(object sender, EventArgs e) { try { string strcon = null; string errormsg = ""; string filename = fupld_Position.FileName; filedatetime = Convert.ToString(DateTime.Now.TimeOfDay) + "_" + filename; filedatetime = filedatetime.Replace("/", "").Replace(":", "."); if (fupld_Position.HasFile) { if (System.IO.Directory.Exists(Server.MapPath("~/IMPORT_EXCEL/")) == false) { System.IO.Directory.CreateDirectory(Server.MapPath("~/IMPORT_EXCEL/")); } fupld_Position.PostedFile.SaveAs(System.IO.Path.Combine(Server.MapPath("~/IMPORT_EXCEL/"), filedatetime)); string filename1 = Server.MapPath("~/IMPORT_EXCEL/") + ("") + (Convert.ToString(filedatetime)); FileInfo fileInfo = new FileInfo(filename1); if (fileInfo.Exists) { string path = MapPath(filename); string ext = Path.GetExtension(path); string type = string.Empty; // set known types based on file extension if (ext != null) { switch (ext.ToLower()) { case ".xls": type = "excel"; break; case ".xlsx": type = "excel"; break; default: type = string.Empty; break; } } if (type == string.Empty) { if (System.IO.Directory.Exists(Server.MapPath("~/IMPORT_EXCEL/")) == true) { string path1 = Server.MapPath("~/IMPORT_EXCEL/") + ("") + (Convert.ToString(filedatetime)); System.IO.File.Delete(path1); } BLL.ShowMessage(this, "Please select the Excel File (Eg: Excel.xlsx). "); return; } } } else { BLL.ShowMessage(this, "Please Select the File to be uploaded"); return; } string strpath = Server.MapPath("~/IMPORT_EXCEL/"); strpath = strpath + filedatetime; // Getting data from excell file to dataset. strcon = "Provider=Microsoft.ACE.OLEDB.12.0;" + "Data Source='" + strpath + "';" + "Extended Properties=Excel 12.0;"; OleDbConnection objConn = null; objConn = new OleDbConnection(strcon); objConn.Open(); DataTable dt_check = objConn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null); string sheetname; if (dt_check == null) { objConn.Close(); Delete_Excel_File(); BLL.ShowMessage(this, "Please select the Correct Excel Template Sheet."); return; } else { sheetname = Convert.ToString(dt_check.Rows[0]["TABLE_NAME"]); } OleDbDataAdapter da = new OleDbDataAdapter("SELECT * FROM [" + sheetname + "]", strcon); da.Fill(ds); ds.Tables[0].Columns.Add("Error Message"); objConn.Close(); DataTable dt = new DataTable(); DataTable dtfail = new DataTable(); string projecttype = null; Int32 rowno = 0; string columnno = null; //Boolean filestatus = true; dtfail.Columns.Add("S.NO", typeof(Int32)); dtfail.Columns.Add("ROWNO", typeof(Int32)); dtfail.Columns.Add("COLUMNS NAME", typeof(string)); //For Checking The Position Name Field Is There or not in the excel sheet if (!(ds.Tables[0].Columns[0].ToString().Trim() == "Name *")) { Delete_Excel_File(); BLL.ShowMessage(this, "Please select the Correct Excel Template Sheet."); return; } //For Checking The Position Description Field Is There or not in the excel sheet if (!(ds.Tables[0].Columns[1].ToString().Trim() == "Description")) { Delete_Excel_File(); BLL.ShowMessage(this, "Please select the Correct Excel Template Sheet."); return; } //For Checking The Availability of Job Field if (!(ds.Tables[0].Columns[2].ToString() == "Job *")) { Delete_Excel_File(); BLL.ShowMessage(this, "Please select the Correct Excel Template Sheet."); return; } //For Checking The Availability of Status if (!(ds.Tables[0].Columns[3].ToString() == "Status *")) { Delete_Excel_File(); BLL.ShowMessage(this, "Please select the Correct Excel Template Sheet."); return; } //For Checking The Availability of Start Date if (!(ds.Tables[0].Columns[4].ToString() == "Start Date *(DD/MM/YYYY)")) { Delete_Excel_File(); BLL.ShowMessage(this, "Please select the Correct Excel Template Sheet."); return; } //For Checking The Availability of End Date if (!(ds.Tables[0].Columns[5].ToString() == "End Date (DD/MM/YYYY)")) { Delete_Excel_File(); BLL.ShowMessage(this, "Please select the Correct Excel Template Sheet."); return; } //For Checking The Availability of the Records In The Excel Sheet if (ds.Tables[0].Rows.Count == 0) { BLL.ShowMessage(this, "Imported Successfully But There is No Record Available!"); Delete_Excel_File(); return; } else { bool IsCorrect = true; bool found = false; int jobid = 0; SMHR_POSITIONS _obj_Smhr_Positions = new SMHR_POSITIONS(); loadDropdown(); //For Validating The Excel Sheet for (int rowindex = 0; rowindex < ds.Tables[0].Rows.Count; rowindex++) { if (Convert.ToString(ds.Tables[0].Rows[rowindex][0]) != string.Empty) { _obj_Smhr_Positions.OPERATION = operation.Check; _obj_Smhr_Positions.POSITIONS_CODE = Convert.ToString(ds.Tables[0].Rows[rowindex][0]); _obj_Smhr_Positions.ORGANISATION_ID = Convert.ToInt32(Session["ORG_ID"]); if (Convert.ToString(BLL.get_Positions(_obj_Smhr_Positions).Rows[0]["Count"]) == "1") { IsCorrect = false; rowno = rowindex + 2; columnno = columnno + "," + "Name *"; errormsg = "Position Name Is Already Exists "; } } if (Convert.ToString(ds.Tables[0].Rows[rowindex][2]) != string.Empty) { for (int count = 0; count < rcmb_PositionsJobs.Items.Count; count++) { if (Convert.ToString(ds.Tables[0].Rows[rowindex][2]) == rcmb_PositionsJobs.Items[count].Text) { found = true; jobid = Convert.ToInt32(rcmb_PositionsJobs.Items[count].Value); } } if (!found) { IsCorrect = false; rowno = rowindex + 2; columnno = columnno + "," + "Job"; if (errormsg != string.Empty) { errormsg = errormsg + "," + "Job Which You Have Entered Is Not Exists "; } else { errormsg = "Job Which You Have Entered Is Not Exists "; } } } if (Convert.ToString(ds.Tables[0].Rows[rowindex][3]) == string.Empty) { IsCorrect = false; rowno = rowindex + 2; columnno = columnno + "," + "Status *"; if (errormsg != string.Empty) { errormsg = errormsg + "," + "Job Status Should Be Active Or In Active "; } else { errormsg = "Job Status Should Be Active Or In Active "; } } else { if (!((Convert.ToString(ds.Tables[0].Rows[rowindex][3]).ToUpper() == "ACTIVE") || (Convert.ToString(ds.Tables[0].Rows[rowindex][3]).ToUpper() == "INACTIVE"))) { IsCorrect = false; rowno = rowindex + 2; columnno = columnno + "," + "Status *"; if (errormsg != string.Empty) { errormsg = errormsg + "," + "Job Status Should Be Active Or In Active "; } else { errormsg = "Job Status Should Be Active Or In Active "; } } } if ((Convert.ToString(ds.Tables[0].Rows[rowindex][4]) != string.Empty)) { if (!(BLL.CheckDateFormat(Convert.ToString(ds.Tables[0].Rows[rowindex][4].ToString())))) { IsCorrect = false; rowno = rowindex + 2; columnno = columnno + "," + "Start Date *(DD/MM/YYYY)"; errormsg = errormsg + "," + "Enter Start Date In The Correct Format "; } } else { IsCorrect = false; rowno = rowindex + 2; columnno = columnno + "," + "Start Date *(DD/MM/YYYY)"; errormsg = errormsg + "," + "Enter Start Date "; } if ((Convert.ToString(ds.Tables[0].Rows[rowindex][4]) != string.Empty) && (Convert.ToString(ds.Tables[0].Rows[rowindex][5]) != string.Empty)) { bool stdatetime = true; if (!(BLL.CheckDateFormat(Convert.ToString(ds.Tables[0].Rows[rowindex]["Start Date *(DD/MM/YYYY)"])))) { stdatetime = false; IsCorrect = false; rowno = rowindex + 2; columnno = columnno + "," + "Start Date *(DD/MM/YYYY)"; errormsg = errormsg + "," + "Enter Correct Date Format For Start Date "; // break; } if (!(BLL.CheckDateFormat(Convert.ToString(ds.Tables[0].Rows[rowindex]["End Date (DD/MM/YYYY)"])))) { stdatetime = false; IsCorrect = false; rowno = rowindex + 2; columnno = columnno + "," + "End Date (DD/MM/YYYY)"; errormsg = errormsg + "," + "Enter Correct Date Format For End Date "; //break; } if (!stdatetime) { if (!(Convert.ToDateTime(ds.Tables[0].Rows[rowindex][4].ToString()) > (Convert.ToDateTime(ds.Tables[0].Rows[rowindex][5].ToString())))) { IsCorrect = false; rowno = rowindex + 2; columnno = columnno + "," + "End Date (DD/MM/YYYY)"; columnno = columnno + "," + "Start Date *(DD/MM/YYYY)"; errormsg = errormsg + "," + "Start Date Should Be Greater Than End Date "; } } } if (!IsCorrect) { DataRow newrow = dtfail.NewRow(); newrow["S.NO"] = dtfail.Rows.Count + 1; newrow["ROWNO"] = rowno; newrow["COLUMNS NAME"] = columnno; dtfail.Rows.Add(newrow); ds.Tables[0].Rows[rowindex]["Error Message"] = errormsg; } // For checking The Duplicate Row in Excel for (int k = 0; k < ds.Tables[0].Rows.Count; k++) { if (ds.Tables[0].Rows[rowindex]["Name *"].ToString().Trim() == ds.Tables[0].Rows[k]["Name *"].ToString().Trim()) { if (rowindex != k) { errormsg = errormsg + "," + " Position Name is repeated in Excel Sheet"; IsCorrect = false; rowno = rowindex + 2; columnno = "Name *"; } } } } if (dtfail.Rows.Count > 0) { Session["dt_fail"] = dtfail; Session["ds_data"] = ds; Delete_Excel_File(); Telerik.Web.UI.RadWindow newwindow = new Telerik.Web.UI.RadWindow(); newwindow.ID = "RadWindow_import"; newwindow.NavigateUrl = "~/Masters/Importresult.aspx"; newwindow.Title = "Import Job Process"; newwindow.Width = 1150; newwindow.Height = 580; newwindow.VisibleOnPageLoad = true; if (RWM_POSITIONPOSTREPLY.Windows.Count > 1) { RWM_POSITIONPOSTREPLY.Windows.RemoveAt(1); } RWM_POSITIONPOSTREPLY.Windows.Add(newwindow); RWM_POSITIONPOSTREPLY.Visible = true; return; } else { // For Dumping Each Record In To The Database for (int xlrows = 0; xlrows < ds.Tables[0].Rows.Count; xlrows++) { _obj_Smhr_Positions.ORGANISATION_ID = Convert.ToInt32(Session["ORG_ID"]); _obj_Smhr_Positions.POSITIONS_CODE = Convert.ToString(ds.Tables[0].Rows[xlrows][0]); _obj_Smhr_Positions.POSITIONS_DESC = Convert.ToString(ds.Tables[0].Rows[xlrows][1]); if (Convert.ToString(ds.Tables[0].Rows[xlrows][2]) != string.Empty) { for (int count = 0; count < rcmb_PositionsJobs.Items.Count; count++) { if (Convert.ToString(ds.Tables[0].Rows[xlrows][2]) == rcmb_PositionsJobs.Items[count].Text) { _obj_Smhr_Positions.POSITIONS_ID = Convert.ToInt32(rcmb_PositionsJobs.Items[count].Value); break; } } } if (Convert.ToString(ds.Tables[0].Rows[xlrows][2]) != string.Empty) { _obj_Smhr_Positions.POSITIONS_JOBSID = jobid; } if (Convert.ToString(ds.Tables[0].Rows[xlrows][3]) != string.Empty) { if (Convert.ToString(ds.Tables[0].Rows[xlrows][3]).ToUpper() == "ACTIVE") { _obj_Smhr_Positions.POSITIONS_STATUS = 0; } else { _obj_Smhr_Positions.POSITIONS_STATUS = 1; } } string sdate = ""; string edate = ""; sdate = ds.Tables[0].Rows[xlrows][4].ToString(); edate = ds.Tables[0].Rows[xlrows][5].ToString(); bool wrongsdformat = sdate.Contains("."); bool wrongedformat = edate.Contains("."); if (wrongsdformat) { sdate = sdate.Replace(".", "/"); } if (wrongedformat) { edate = edate.Replace(".", "/"); } _obj_Smhr_Positions.SDATE = sdate; _obj_Smhr_Positions.EDATE = edate; _obj_Smhr_Positions.CREATEDBY = Convert.ToInt32(Session["USER_ID"]); _obj_Smhr_Positions.CREATEDDATE = DateTime.Now; _obj_Smhr_Positions.LASTMDFBY = Convert.ToInt32(Session["USER_ID"]); _obj_Smhr_Positions.LASTMDFDATE = DateTime.Now; _obj_Smhr_Positions.ORGANISATION_ID = Convert.ToInt32(Session["ORG_ID"]); _obj_Smhr_Positions.OPERATION = operation.Check; _obj_Smhr_Positions.POSITIONS_CODE = Convert.ToString(ds.Tables[0].Rows[xlrows][0]); _obj_Smhr_Positions.ORGANISATION_ID = Convert.ToInt32(Session["ORG_ID"]); if (Convert.ToString(BLL.get_Positions(_obj_Smhr_Positions).Rows[0]["Count"]) == "1") { continue; //IsCorrect = true; } else { _obj_Smhr_Positions.OPERATION = operation.Insert1; if (BLL.set_Positions(_obj_Smhr_Positions)) { IsCorrect = true; } } } Rm_PO_page.SelectedIndex = 0; LoadGrid(); Rm_PO_page.DataBind(); if (IsCorrect) { BLL.ShowMessage(this, "Information Uploaded SuccessFully"); } } } } catch (Exception ex) { SMHR.BLL.Error_Log(Session["USER_ID"].ToString(), ex.TargetSite.ToString(), ex.Message.Replace("'", "''"), "frmposition.aspx", ex.StackTrace, DateTime.Now); Response.Redirect("Frm_ErrorPage.aspx"); } }
protected void Btn_upload_Click(object sender, EventArgs e) { try { _obj_vamt.OPERATION = operation.Select; _obj_vamt.ORGANISATION_ID = Convert.ToInt32(Session["ORG_ID"]); if ((rcmb_Businessunit.SelectedIndex > 0) && (rcmb_Financialperiod.SelectedIndex > 0)) { _obj_vamt.BUID = Convert.ToInt32(rcmb_Businessunit.SelectedValue); dt_Result = BLL.get_Employeevariableamt(_obj_vamt);//GETTING ALL EMPLOYEES WHO ARE HAVING VARIABLE PAY } _obj_vamt.OPERATION = operation.Check; _obj_vamt.ORGANISATION_ID = Convert.ToInt32(Session["ORG_ID"]); dt_resultcomp = BLL.Get_Components(_obj_vamt); string strcon = null; string strfilename1 = FileUpload1.FileName; strfilename2 = Convert.ToString(DateTime.Now.TimeOfDay) + "_" + strfilename1; strfilename2 = strfilename2.Replace("/", "").Replace(":", "."); if (FileUpload1.HasFile) { if (System.IO.Directory.Exists(Server.MapPath("~/IMPORT_EXCEL/")) == false) { System.IO.Directory.CreateDirectory(Server.MapPath("~/IMPORT_EXCEL/")); } FileUpload1.PostedFile.SaveAs(System.IO.Path.Combine(Server.MapPath("~/IMPORT_EXCEL/"), strfilename2)); string filename1 = Server.MapPath("~/IMPORT_EXCEL/") + ("") + (Convert.ToString(strfilename2)); FileInfo fileInfo = new FileInfo(filename1); if (fileInfo.Exists) { string path = MapPath(strfilename1); // string name = Path.GetFileName( path ); string ext = Path.GetExtension(path); string type = string.Empty; if (ext != null) { switch (ext.ToLower()) { case ".xls": type = "excel"; break; case ".xlsx": type = "excel"; break; default: type = string.Empty; break; } } if (type == string.Empty) { if (System.IO.Directory.Exists(Server.MapPath("~/IMPORT_EXCEL/")) == true) { string path1 = Server.MapPath("~/IMPORT_EXCEL/") + ("") + (Convert.ToString(strfilename2)); System.IO.File.Delete(path1); } BLL.ShowMessage(this, "Please select the Excel File (Eg: Excel.xlsx). "); return; } } } else { BLL.ShowMessage(this, "Please Select the File to be uploaded"); return; } string strpath = Server.MapPath("~/IMPORT_EXCEL/"); strpath = strpath + strfilename2; // Getting data from excell file to dataset. strcon = "Provider=Microsoft.ACE.OLEDB.12.0;" + "Data Source='" + strpath + "';" + "Extended Properties=Excel 12.0;"; OleDbConnection objConn = null; objConn = new OleDbConnection(strcon); objConn.Open(); DataTable dt_chk2 = objConn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null); string sheetname; if (dt_chk2 == null) { objConn.Close(); Delete_Excel_File(); BLL.ShowMessage(this, "Please select the Correct Excel Template Sheet."); return; } else { sheetname = Convert.ToString(dt_chk2.Rows[0]["TABLE_NAME"]); } OleDbDataAdapter da = new OleDbDataAdapter("SELECT * FROM [" + sheetname + "]", strcon); da.Fill(ds); ds.Tables[0].Columns.Add("Error Message"); objConn.Close(); DataTable dt = new DataTable(); DataTable dtfail = new DataTable(); string errormsg = string.Empty; //string projecttype = null; Int32 rowno = 0; //DateTime dat; string columnno = null; //string projname = null; Boolean filestatus = true; Boolean filestatus1 = true; dtfail.Columns.Add("S.NO", typeof(Int32)); dtfail.Columns.Add("ROWNO", typeof(Int32)); dtfail.Columns.Add("COLUMNS NAMES", typeof(string)); if (ds.Tables[0].Columns[0].ToString().Trim() == "EmployeeId*") { } else { Delete_Excel_File(); BLL.ShowMessage(this, "Please select the Correct Excel Template Sheet."); return; } if (ds.Tables[0].Columns[1].ToString().Trim() == "VariablePayComponent*") { } else { Delete_Excel_File(); BLL.ShowMessage(this, "Please select the Correct Excel Template Sheet."); return; } if (ds.Tables[0].Columns[2].ToString().Trim() == "Percentage*") { } else { Delete_Excel_File(); BLL.ShowMessage(this, "Please select the Correct Excel Template Sheet."); return; } if (ds.Tables[0].Rows.Count == 0) { Delete_Excel_File(); BLL.ShowMessage(this, "Successfully processed Excel file. No Records are Imported."); return; } DataTable dt_empexist = new DataTable(); DataTable dt_empid = new DataTable(); DataTable dt_failm = new DataTable(); dt_failm.Columns.Add("S.NO", typeof(Int32)); dt_failm.Columns.Add("ROWNO", typeof(Int32)); dt_failm.Columns.Add("COLUMNS NAMES", typeof(string)); DataColumn dc = new DataColumn(); //dc.ColumnName = "Component"; //dc.DataType = typeof(string); //dt_empexist.Columns.Add(dc); DataColumn dce0 = new DataColumn(); dce0.ColumnName = "EmpId"; dce0.DataType = typeof(string); dt_empid.Columns.Add(dce0); DataColumn dc1 = new DataColumn(); dc1.ColumnName = "Percentage"; dc1.DataType = typeof(double); dt_empexist.Columns.Add(dc1); DataColumn dc2 = new DataColumn(); dc2.ColumnName = "Empcode"; dc2.DataType = typeof(string); dt_empexist.Columns.Add(dc2); //@@@@@@@@@@@@@@@@@@ DataTable dt_empexist1 = new DataTable(); DataColumn dcl2 = new DataColumn(); dcl2.ColumnName = "Empcode"; dcl2.DataType = typeof(string); dt_empexist1.Columns.Add(dcl2); DataColumn dcl1 = new DataColumn(); dcl1.ColumnName = "Percentage"; dcl1.DataType = typeof(double); dt_empexist1.Columns.Add(dcl1); DataColumn dcl3 = new DataColumn(); dcl3.ColumnName = "ErrorMessage"; dcl3.DataType = typeof(string); dt_empexist1.Columns.Add(dcl3); bool varempcomp = false; for (int v = 0; v < ds.Tables[0].Rows.Count; v++) { for (int m = 0; m < ds.Tables[0].Rows.Count; m++) { if ((ds.Tables[0].Rows[v]["EmployeeId*"].ToString().Trim() == ds.Tables[0].Rows[m]["EmployeeId*"].ToString().Trim()) && (ds.Tables[0].Rows[v]["VariablePayComponent*"].ToString().Trim() == ds.Tables[0].Rows[m]["VariablePayComponent*"].ToString().Trim())) { if (v != m) { varempcomp = true; errormsg = "VariablePayComponent does not exist"; filestatus = false; rowno = v + 2; columnno = "VariablePayComponent*"; DataRow newrow = dtfail.NewRow(); newrow["S.NO"] = dtfail.Rows.Count + 1; newrow["ROWNO"] = rowno; newrow["COLUMNS NAMES"] = columnno; dtfail.Rows.Add(newrow); ds.Tables[0].Rows[v]["Error Message"] = errormsg; } } } } if (!(varempcomp)) { for (int p = 0; p < ds.Tables[0].Rows.Count; p++) { bool found1 = false; int x = 0; int per = 0; DataRow dr = dt_empexist.NewRow(); string EMP_CODE1 = string.Empty; // dr[0] = empcomponent; if (ds.Tables[0].Rows[p]["EmployeeId*"].ToString().Trim() != "") { EMP_CODE1 = ds.Tables[0].Rows[p]["EmployeeId*"].ToString().Trim(); x = Convert.ToInt32(ds.Tables[0].Rows[p]["Percentage*"]); } for (int k = 0; k < ds.Tables[0].Rows.Count; k++) { if (ds.Tables[0].Rows[p]["EmployeeId*"].ToString().Trim() == ds.Tables[0].Rows[k]["EmployeeId*"].ToString().Trim()) { if (p != k) { int y = Convert.ToInt32(ds.Tables[0].Rows[k]["Percentage*"]); per = per + y; } } } x = x + per; // compare the existance code which was recorded for (int rowsrepeated = 0; rowsrepeated < dt_empexist.Rows.Count; rowsrepeated++) { if (dt_empexist.Rows[rowsrepeated][1].ToString() == EMP_CODE1) { found1 = true; break; } } if (found1 == false) { dr[0] = x; // x = x + percentage1; dr[1] = EMP_CODE1; dt_empexist.Rows.Add(dr); } } for (int b = 0; b < dt_empexist.Rows.Count; b++) { errormsg = string.Empty; DataRow dr = dt_empexist1.NewRow(); if (Convert.ToInt32(dt_empexist.Rows[b]["Percentage"]) != 100) { filestatus = false; errormsg = "Total Variable Componentpercentage should be 100 for this employee"; dr[0] = dt_empexist.Rows[b]["Empcode"].ToString().Trim(); dr[1] = Convert.ToInt32(dt_empexist.Rows[b]["Percentage"]); dr[2] = errormsg; dt_empexist1.Rows.Add(dr); } } for (int msg = 0; msg < dt_empexist1.Rows.Count; msg++) { for (int g = 0; g < ds.Tables[0].Rows.Count; g++) { if (dt_empexist1.Rows[msg]["Empcode"].ToString() == ds.Tables[0].Rows[g]["EmployeeId*"].ToString()) { errormsg = "Employee Does Not exist"; filestatus1 = false; rowno = g + 2; columnno = "EmployeeId*"; } if (filestatus1 == false) { DataRow newrow = dt_failm.NewRow(); newrow["S.NO"] = dt_failm.Rows.Count + 1; newrow["ROWNO"] = rowno; newrow["COLUMNS NAMES"] = columnno; dt_failm.Rows.Add(newrow); // ds.Tables[0].Rows[i]["Error Message"] = errormsg; } filestatus1 = true; } } for (int i = 0; i < ds.Tables[0].Rows.Count; i++) { bool found = false; errormsg = string.Empty; columnno = string.Empty; //int count = 0; bool EMPCODE_EXISTS = false; if (ds.Tables[0].Rows[i]["EmployeeId*"].ToString().Trim() != "") { // for looping the empcode for checking of the existence of the employee for that businessunit string EMP_CODE = ds.Tables[0].Rows[i]["EmployeeId*"].ToString().Trim(); for (int Rows = 0; Rows < dt_Result.Rows.Count; Rows++) { // for checking employee existance whether exel employee is having variable pay or not string EMP_ID = dt_Result.Rows[Rows]["EMP_NAME"].ToString(); int CUT = EMP_ID.LastIndexOf("-"); string EMP_CODES = EMP_ID.Substring(0, CUT); if (EMP_CODES == EMP_CODE) { // int x = 0; EMPCODE_EXISTS = true; } } if (!(EMPCODE_EXISTS)) { errormsg = "Employee Does Not exist"; filestatus = false; rowno = i + 2; columnno = "EmployeeId*"; } } else { errormsg = "Enter EmployeeId"; filestatus = false; rowno = i + 2; columnno = "EmployeeId*"; } if (ds.Tables[0].Rows[i]["VariablePayComponent*"].ToString().Trim() != "") { bool varpaycomp1 = false; string empcomponent = ds.Tables[0].Rows[i]["VariablePayComponent*"].ToString().Trim(); for (int k = 0; k < dt_resultcomp.Rows.Count; k++) { if (empcomponent == dt_resultcomp.Rows[k]["SMHR_VPCOMP_COMPNAME"].ToString()) { varpaycomp1 = true; } } if (varpaycomp1 == false) { errormsg = errormsg + "," + "VariablePayComponent does not exist"; filestatus = false; rowno = i + 2; columnno = "VariablePayComponent*"; } } else { errormsg = errormsg + "," + "Enter VariablePayComponent "; filestatus = false; rowno = i + 2; columnno = "VariablePayComponent*"; } if (ds.Tables[0].Rows[i]["Percentage*"].ToString().Trim() != "") { int VPMIN = 0; int VPMAX = 0; int SMVPCOMP_ID = 0; bool varpaycomp = false; string empcomponent1 = ds.Tables[0].Rows[i]["VariablePayComponent*"].ToString().Trim(); int percentage1 = Convert.ToInt32(ds.Tables[0].Rows[i]["Percentage*"].ToString().Trim()); for (int k = 0; k < dt_resultcomp.Rows.Count; k++) { if (empcomponent1 == dt_resultcomp.Rows[k]["SMHR_VPCOMP_COMPNAME"].ToString()) { SMVPCOMP_ID = Convert.ToInt32(dt_resultcomp.Rows[k]["SMHR_VPCOMP_ID"]); VPMIN = Convert.ToInt32(dt_resultcomp.Rows[k]["SMHR_VPCOMP_MIN"]); VPMAX = Convert.ToInt32(dt_resultcomp.Rows[k]["SMHR_VPCOMP_MAX"]); varpaycomp = true; } } if (!((percentage1 >= VPMIN) && (percentage1 <= VPMAX))) { // string min = dt_resultcomp.Rows[exlrows]["SMHR_VPCOMP_MIN"].ToString(); //string max = dt_resultcomp.Rows[exlrows]["SMHR_VPCOMP_MAX"].ToString(); errormsg = errormsg + "," + "Percentage you have entered for variable component is out of range:" + "It Should be in Between(" + VPMIN + "," + VPMAX + ")"; filestatus = false; rowno = i + 2; columnno = "Percentage*"; } } else { errormsg = errormsg + "," + "Enter Percentage "; filestatus = false; rowno = i + 2; columnno = "Percentage*"; } if (filestatus == false) { DataRow newrow = dtfail.NewRow(); newrow["S.NO"] = dtfail.Rows.Count + 1; newrow["ROWNO"] = rowno; newrow["COLUMNS NAMES"] = columnno; dtfail.Rows.Add(newrow); ds.Tables[0].Rows[i]["Error Message"] = errormsg; } } } if (dtfail.Rows.Count > 0) { if (dtfail.Rows[0]["COLUMNS NAMES"].ToString() != string.Empty) { //for (int d = 0; d < dtfail.Rows.Count; d++) //{ // for (int c = 0; c < dt_empexist1.Rows.Count; c++) // { // if (ds.Tables[0].Rows[d]["EmployeeId*"].ToString().Trim() == dt_empexist1.Rows[c]["Empcode"].ToString().Trim()) // { // ds.Tables[0].Rows[d]["Error Message"] = ds.Tables[0].Rows[d]["Error Message"].ToString() + "," + dt_empexist1.Rows[c]["ErrorMessage"].ToString(); // // dtfail.Rows[d]["COLUMNS NAMES"] = dt_failm.Rows[d]["COLUMNS NAMES"].ToString() + dt_failm.Rows[c]["COLUMNS NAMES"].ToString(); // } // } //} Session["dt_fail"] = dtfail; Session["ds_data"] = ds; Delete_Excel_File(); //LinkButton lnk_Import_process = (LinkButton)RadPanelBar1.FindItemByValue("AddAttachment").FindControl("lnk_Import_process"); Telerik.Web.UI.RadWindow newwindow = new Telerik.Web.UI.RadWindow(); // RWM_POSTREPLY.Windows.Remove(newwindow); newwindow.ID = "RadWindow_import"; newwindow.NavigateUrl = "~/Payroll/frm_AttendanceImportProcess.aspx"; newwindow.Title = "Import Process"; newwindow.Width = 1150; newwindow.Height = 580; newwindow.VisibleOnPageLoad = true; if (RWM_POSTREPLY1.Windows.Count > 1) { RWM_POSTREPLY1.Windows.RemoveAt(1); } RWM_POSTREPLY1.Windows.Add(newwindow); RWM_POSTREPLY1.Visible = true; return; } else if (dtfail.Rows[0]["COLUMNS NAMES"].ToString() == string.Empty) { for (int d = 0; d < dtfail.Rows.Count; d++) { for (int c = 0; c < dt_empexist1.Rows.Count; c++) { if (ds.Tables[0].Rows[d]["EmployeeId*"].ToString().Trim() == dt_empexist1.Rows[c]["Empcode"].ToString().Trim()) { ds.Tables[0].Rows[d]["Error Message"] = ds.Tables[0].Rows[d]["Error Message"].ToString() + "," + dt_empexist1.Rows[c]["ErrorMessage"].ToString(); // dtfail.Rows[d]["COLUMNS NAMES"] = dt_failm.Rows[d]["COLUMNS NAMES"].ToString() + dt_failm.Rows[c]["COLUMNS NAMES"].ToString(); } } } Session["dt_fail"] = dt_failm; Session["ds_data"] = ds; Delete_Excel_File(); //LinkButton lnk_Import_process = (LinkButton)RadPanelBar1.FindItemByValue("AddAttachment").FindControl("lnk_Import_process"); Telerik.Web.UI.RadWindow newwindow = new Telerik.Web.UI.RadWindow(); // RWM_POSTREPLY.Windows.Remove(newwindow); newwindow.ID = "RadWindow_import"; newwindow.NavigateUrl = "~/Payroll/frm_AttendanceImportProcess.aspx"; newwindow.Title = "Import Process"; newwindow.Width = 1150; newwindow.Height = 580; newwindow.VisibleOnPageLoad = true; if (RWM_POSTREPLY1.Windows.Count > 1) { RWM_POSTREPLY1.Windows.RemoveAt(1); } RWM_POSTREPLY1.Windows.Add(newwindow); RWM_POSTREPLY1.Visible = true; return; } } else { int emp_ID1 = 0; bool exists = false; bool status = false; bool et = false; for (int i = 0; i < ds.Tables[0].Rows.Count; i++) { SMHR_EMPLOYEE1 _obj_SMHR_EMPLOYEE1 = new SMHR_EMPLOYEE1(); _obj_SMHR_EMPLOYEE1.MODE = 8; _obj_SMHR_EMPLOYEE1.EMP_ID = ds.Tables[0].Rows[i]["EmployeeId*"].ToString().Trim(); _obj_SMHR_EMPLOYEE1.ORGID = Convert.ToInt32(Session["ORG_ID"]); DataTable dtempid22 = Pms_Bll.get_Employee1(_obj_SMHR_EMPLOYEE1); if (dtempid22.Rows.Count != 0) { emp_ID1 = Convert.ToInt32(dtempid22.Rows[0]["emp_id"]); } _obj_vamt.EMP_ID = emp_ID1; _obj_vamt.ORGANISATION_ID = Convert.ToInt32(Session["ORG_ID"]); _obj_vamt.BUID = Convert.ToInt32(rcmb_Businessunit.SelectedValue); _obj_vamt.financial_period = Convert.ToInt32(rcmb_Financialperiod.SelectedValue); _obj_vamt.CREATEDBY = Convert.ToInt32(Session["USER_ID"]); _obj_vamt.LASTMDFBY = Convert.ToInt32(Session["USER_ID"]); string name = ds.Tables[0].Rows[i]["VariablePayComponent*"].ToString(); for (int comp = 0; comp < dt_resultcomp.Rows.Count; comp++) { if (name == dt_resultcomp.Rows[comp]["SMHR_VPCOMP_COMPNAME"].ToString()) { _obj_vamt.component_id = Convert.ToInt32(dt_resultcomp.Rows[comp]["SMHR_VPCOMP_ID"].ToString()); } } for (int empid = 0; empid < dt_empid.Rows.Count; empid++) { if (emp_ID1 == Convert.ToInt32(dt_empid.Rows[empid][0].ToString())) { exists = true; } } _obj_vamt.component_percentage = Convert.ToInt32(ds.Tables[0].Rows[i]["Percentage*"]); if (!exists) { _obj_vamt.OPERATION = operation.Delete; et = BLL.set_Component(_obj_vamt); } //_obj_vamt.OPERATION = operation.Insert; _obj_vamt.OPERATION = operation.MODE1; status = BLL.set_Component(_obj_vamt); //DataRow dr = dt_empid.NewRow(); //dr[0] = emp_ID1; //dt_empid.Rows.Add(dr); } if (status == true) { BLL.ShowMessage(this, "Employee Components Set for the Selected Employees"); } } } catch (Exception ex) { SMHR.BLL.Error_Log(Session["USER_ID"].ToString(), ex.TargetSite.ToString(), ex.Message.Replace("'", "''"), "frm_ImportEmpcomponents", ex.StackTrace, DateTime.Now); Response.Redirect("~/Frm_ErrorPage.aspx"); } }
protected void Button1_Click(object sender, EventArgs e) { try { string strcon = null; string strfilename1 = FileUpload1.FileName; strfilename2 = Convert.ToString(DateTime.Now.TimeOfDay) + "_" + strfilename1; strfilename2 = strfilename2.Replace("/", "").Replace(":", "."); if (FileUpload1.HasFile) { if (System.IO.Directory.Exists(Server.MapPath("~/IMPORT_EXCEL/")) == false) { System.IO.Directory.CreateDirectory(Server.MapPath("~/IMPORT_EXCEL/")); } FileUpload1.PostedFile.SaveAs(System.IO.Path.Combine(Server.MapPath("~/IMPORT_EXCEL/"), strfilename2)); string filename1 = Server.MapPath("~/IMPORT_EXCEL/") + ("") + (Convert.ToString(strfilename2)); FileInfo fileInfo = new FileInfo(filename1); if (fileInfo.Exists) { string path = MapPath(strfilename1); // string name = Path.GetFileName( path ); string ext = Path.GetExtension(path); string type = string.Empty; if (ext != null) { switch (ext.ToLower()) { case ".xls": type = "excel"; break; case ".xlsx": type = "excel"; break; default: type = string.Empty; break; } } if (type == string.Empty) { if (System.IO.Directory.Exists(Server.MapPath("~/IMPORT_EXCEL/")) == true) { string path1 = Server.MapPath("~/IMPORT_EXCEL/") + ("") + (Convert.ToString(strfilename2)); System.IO.File.Delete(path1); } BLL.ShowMessage(this, "Please select the Excel File (Eg: Excel.xlsx). "); return; } } } else { BLL.ShowMessage(this, "Please Select the File to be uploaded"); return; } string strpath = Server.MapPath("~/IMPORT_EXCEL/"); strpath = strpath + strfilename2; // Getting data from excell file to dataset. strcon = "Provider=Microsoft.ACE.OLEDB.12.0;" + "Data Source='" + strpath + "';" + "Extended Properties=Excel 12.0;"; OleDbConnection objConn = null; objConn = new OleDbConnection(strcon); objConn.Open(); DataTable dt_chk2 = objConn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null); string sheetname; if (dt_chk2 == null) { objConn.Close(); Delete_Excel_File(); BLL.ShowMessage(this, "Please select the Correct Excel Template Sheet."); return; } else { sheetname = Convert.ToString(dt_chk2.Rows[0]["TABLE_NAME"]); } OleDbDataAdapter da = new OleDbDataAdapter("SELECT * FROM [" + sheetname + "]", strcon); da.Fill(ds); ds.Tables[0].Columns.Add("Error Message"); objConn.Close(); DataTable dt = new DataTable(); DataTable dtfail = new DataTable(); string errormsg = string.Empty; string projecttype = null; Int32 rowno = 0; DateTime dat; string columnno = null; string projname = null; Boolean filestatus = true; dtfail.Columns.Add("S.NO", typeof(Int32)); dtfail.Columns.Add("ROWNO", typeof(Int32)); dtfail.Columns.Add("COLUMNS NAMES", typeof(string)); if (ds.Tables[0].Columns[0].ToString().Trim() == "Component Name*") { } else { Delete_Excel_File(); BLL.ShowMessage(this, "Please select the Correct Excel Template Sheet."); return; } if (ds.Tables[0].Columns[1].ToString().Trim() == "Component Description") { } else { Delete_Excel_File(); BLL.ShowMessage(this, "Please select the Correct Excel Template Sheet."); return; } if (ds.Tables[0].Columns[2].ToString().Trim() == "Status") { } else { Delete_Excel_File(); BLL.ShowMessage(this, "Please select the Correct Excel Template Sheet."); return; } if (ds.Tables[0].Columns[3].ToString().Trim() == "Minimum Percentage*") { } else { Delete_Excel_File(); BLL.ShowMessage(this, "Please select the Correct Excel Template Sheet."); return; } if (ds.Tables[0].Columns[4].ToString().Trim() == "Max Percentage*") { } else { Delete_Excel_File(); BLL.ShowMessage(this, "Please select the Correct Excel Template Sheet."); return; } if (ds.Tables[0].Rows.Count == 0) { Delete_Excel_File(); BLL.ShowMessage(this, "Successfully processed Excel file. No Records are Imported."); return; } for (int i = 0; i < ds.Tables[0].Rows.Count; i++) { errormsg = string.Empty; columnno = string.Empty; if (ds.Tables[0].Rows[i]["Component Name*"].ToString().Trim() != "") { } else { errormsg = "enter component name"; filestatus = false; rowno = i + 2; columnno = "Component Name*"; } for (int k = 0; k < ds.Tables[0].Rows.Count; k++) { if (ds.Tables[0].Rows[i]["Component Name*"].ToString().Trim() == ds.Tables[0].Rows[k]["Component Name*"].ToString().Trim()) { if (i != k) { errormsg = errormsg + "," + "Component Name with this Name is repeated in Excel Sheet"; filestatus = false; rowno = i + 2; columnno = "Component Name*"; } } } if (ds.Tables[0].Rows[i]["Minimum Percentage*"].ToString().Trim() != "") { if (Convert.ToInt32(ds.Tables[0].Rows[i]["Minimum Percentage*"]) < 1000) { } else { errormsg = errormsg + "," + "Minimum Percentage should be three digits only"; filestatus = false; rowno = i + 2; columnno = "Minimum Percentage*"; } } else { errormsg = errormsg + "," + "Enter Minimum Percentage"; filestatus = false; rowno = i + 2; columnno = "Minimum Percentage*"; } for (int p = 0; p < ds.Tables[0].Rows.Count; p++) { if (Convert.ToInt32(ds.Tables[0].Rows[i]["Minimum Percentage*"]) < Convert.ToInt32(ds.Tables[0].Rows[p]["Max Percentage*"])) { //if (i != p) //{ // errormsg = errormsg + "," + "Minimum Percentage should be less than Max percentage"; // filestatus = false; // rowno = i + 2; // columnno = "Component Name*"; //} } else { errormsg = errormsg + "," + "Minimum Percentage should be less than Max percentage"; filestatus = false; rowno = i + 2; columnno = "Minimum Percentage*"; } } if (ds.Tables[0].Rows[i]["Max Percentage*"].ToString().Trim() != "") { if (Convert.ToInt32(ds.Tables[0].Rows[i]["Max Percentage*"]) < 1000) { } else { errormsg = errormsg + "," + "Max Percentage should be three digits only"; filestatus = false; rowno = i + 2; columnno = "Max Percentage*"; } } else { errormsg = errormsg + "," + "Enter Max Percentage"; filestatus = false; rowno = i + 2; columnno = "Max Percentage*"; } if (filestatus == false) { DataRow newrow = dtfail.NewRow(); newrow["S.NO"] = dtfail.Rows.Count + 1; newrow["ROWNO"] = rowno; newrow["COLUMNS NAMES"] = columnno; dtfail.Rows.Add(newrow); ds.Tables[0].Rows[i]["Error Message"] = errormsg; } } if (dtfail.Rows.Count > 0) { Session["dt_fail"] = dtfail; Session["ds_data"] = ds; Delete_Excel_File(); //LinkButton lnk_Import_process = (LinkButton)RadPanelBar1.FindItemByValue("AddAttachment").FindControl("lnk_Import_process"); Telerik.Web.UI.RadWindow newwindow = new Telerik.Web.UI.RadWindow(); // RWM_POSTREPLY.Windows.Remove(newwindow); newwindow.ID = "RadWindow_import"; newwindow.NavigateUrl = "~/Payroll/frm_AttendanceImportProcess.aspx"; newwindow.Title = "Import Process"; newwindow.Width = 1150; newwindow.Height = 580; newwindow.VisibleOnPageLoad = true; if (RWM_POSTREPLY1.Windows.Count > 1) { RWM_POSTREPLY1.Windows.RemoveAt(1); } RWM_POSTREPLY1.Windows.Add(newwindow); RWM_POSTREPLY1.Visible = true; return; } else { bool status = false; for (int i = 0; i < ds.Tables[0].Rows.Count; i++) { _obj_vpc.ORGANISATION_ID = Convert.ToInt32(Session["ORG_ID"]); _obj_vpc.component_desc = Convert.ToString(ds.Tables[0].Rows[i]["Component Description"]).Trim(); _obj_vpc.component_name = Convert.ToString(ds.Tables[0].Rows[i]["Component Name*"]).Trim(); _obj_vpc.component_max = Convert.ToInt32(ds.Tables[0].Rows[i]["Max Percentage*"]); _obj_vpc.component_min = Convert.ToInt32(ds.Tables[0].Rows[i]["Minimum Percentage*"]); if (ds.Tables[0].Rows[i]["Status"].ToString() == "") { _obj_vpc.component_status = false; } else { _obj_vpc.component_status = Convert.ToBoolean(ds.Tables[0].Rows[i]["Status"]); } _obj_vpc.CREATEDBY = Convert.ToInt32(Session["USER_ID"]); _obj_vpc.LASTMDFBY = Convert.ToInt32(Session["USER_ID"]); _obj_vpc.OPERATION = operation.Insert; status = BLL.set_Component(_obj_vpc); //if (status) // BLL.ShowMessage(this, "Information Saved Successfully"); //else // BLL.ShowMessage(this, "Error Occured"); //LoadGrid(); //rg_VariablepayComponents.DataBind(); } if (status) { BLL.ShowMessage(this, "Information Saved Successfully"); } LoadGrid(); rg_VariablepayComponents.DataBind(); } } // catch (Exception ex) { SMHR.BLL.Error_Log(Session["USER_ID"].ToString(), ex.TargetSite.ToString(), ex.Message.Replace("'", "''"), "frm_VariableComponents", ex.StackTrace, DateTime.Now); Response.Redirect("~/Frm_ErrorPage.aspx"); } }
protected void Btn_Imp_Category_click(object sender, EventArgs e) { try { //written by Rajasekhar //To Import category Excel Sheet string strcon = null; string strfilename1 = FileUpload1.FileName; strfilename2 = Convert.ToString(DateTime.Now.TimeOfDay) + "_" + strfilename1; strfilename2 = strfilename2.Replace("/", "").Replace(":", "."); if (FileUpload1.HasFile) { if (System.IO.Directory.Exists(Server.MapPath("~/IMPORT_EXCEL/")) == false) { System.IO.Directory.CreateDirectory(Server.MapPath("~/IMPORT_EXCEL/")); } FileUpload1.PostedFile.SaveAs(System.IO.Path.Combine(Server.MapPath("~/IMPORT_EXCEL/"), strfilename2)); string filename1 = Server.MapPath("~/IMPORT_EXCEL/") + ("") + (Convert.ToString(strfilename2)); FileInfo fileInfo = new FileInfo(filename1); if (fileInfo.Exists) { string path = MapPath(strfilename1); // string name = Path.GetFileName( path ); string ext = Path.GetExtension(path); string type = string.Empty; // set known types based on file extension if (ext != null) { switch (ext.ToLower()) { case ".xls": type = "excel"; break; case ".xlsx": type = "excel"; break; default: type = string.Empty; break; } } if (type == string.Empty) { if (System.IO.Directory.Exists(Server.MapPath("~/IMPORT_EXCEL/")) == true) { string path1 = Server.MapPath("~/IMPORT_EXCEL/") + ("") + (Convert.ToString(strfilename2)); System.IO.File.Delete(path1); } BLL.ShowMessage(this, "Please select the Excel File (Eg: Excel.xlsx). "); return; } } } else { BLL.ShowMessage(this, "Please Select the File to be uploaded"); return; } string strpath = Server.MapPath("~/IMPORT_EXCEL/"); strpath = strpath + strfilename2; // Getting data from excell file to dataset. strcon = "Provider=Microsoft.ACE.OLEDB.12.0;" + "Data Source='" + strpath + "';" + "Extended Properties=Excel 12.0;"; OleDbConnection objConn = null; objConn = new OleDbConnection(strcon); objConn.Open(); DataTable dt_chk2 = objConn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null); string sheetname; if (dt_chk2 == null) { objConn.Close(); Delete_Excel_File(); BLL.ShowMessage(this, "Please select the Correct Excel Template Sheet."); return; } else { sheetname = Convert.ToString(dt_chk2.Rows[0]["TABLE_NAME"]); } OleDbDataAdapter da = new OleDbDataAdapter("SELECT * FROM [" + sheetname + "]", strcon); da.Fill(ds); ds.Tables[0].Columns.Add("Error Message"); objConn.Close(); DataTable dt = new DataTable(); DataTable dtfail = new DataTable(); string errormsg = string.Empty; string projecttype = null; Int32 rowno = 0; DateTime dat; string columnno = null; string projname = null; Boolean filestatus = true; dtfail.Columns.Add("S.NO", typeof(Int32)); dtfail.Columns.Add("ROWNO", typeof(Int32)); dtfail.Columns.Add("COLUMNS NAMES", typeof(string)); if (ds.Tables[0].Columns[0].ToString().Trim() == "Name*") { } else { Delete_Excel_File(); BLL.ShowMessage(this, "Please select the Correct Excel Template Sheet."); return; } if (ds.Tables[0].Columns[1].ToString().Trim() == "Description") { } else { Delete_Excel_File(); BLL.ShowMessage(this, "Please select the Correct Excel Template Sheet."); return; } if (ds.Tables[0].Columns[2].ToString().Trim() == "OverTime Enabled") { } else { Delete_Excel_File(); BLL.ShowMessage(this, "Please select the Correct Excel Template Sheet."); return; } if (ds.Tables[0].Columns[3].ToString().Trim() == "Bank Info") { } else { Delete_Excel_File(); BLL.ShowMessage(this, "Please select the Correct Excel Template Sheet."); return; } if (ds.Tables[0].Columns[4].ToString().Trim() == "Currency") { } else { Delete_Excel_File(); BLL.ShowMessage(this, "Please select the Correct Excel Template Sheet."); return; } if (ds.Tables[0].Columns[5].ToString().Trim() == "Age") { } else { Delete_Excel_File(); BLL.ShowMessage(this, "Please select the Correct Excel Template Sheet."); return; } if (ds.Tables[0].Columns[6].ToString().Trim() == "DateFormat") { } else { Delete_Excel_File(); BLL.ShowMessage(this, "Please select the Correct Excel Template Sheet."); return; } if (ds.Tables[0].Columns[7].ToString().Trim() == "Address") { } else { Delete_Excel_File(); BLL.ShowMessage(this, "Please select the Correct Excel Template Sheet."); return; } if (ds.Tables[0].Columns[8].ToString().Trim() == "Country") { } else { Delete_Excel_File(); BLL.ShowMessage(this, "Please select the Correct Excel Template Sheet."); return; } if (ds.Tables[0].Columns[9].ToString().Trim() == "Fiscal Year") { } else { Delete_Excel_File(); BLL.ShowMessage(this, "Please select the Correct Excel Template Sheet."); return; } if (ds.Tables[0].Columns[10].ToString().Trim() == "Calendar") { } else { Delete_Excel_File(); BLL.ShowMessage(this, "Please select the Correct Excel Template Sheet."); return; } if (ds.Tables[0].Columns[11].ToString().Trim() == "Payment Methods") { } else { Delete_Excel_File(); BLL.ShowMessage(this, "Please select the Correct Excel Template Sheet."); return; } if (ds.Tables[0].Columns[12].ToString().Trim() == "Localisation") { } else { Delete_Excel_File(); BLL.ShowMessage(this, "Please select the Correct Excel Template Sheet."); return; } if (ds.Tables[0].Rows.Count == 0) { Delete_Excel_File(); BLL.ShowMessage(this, "Successfully processed Excel file. No Records are Imported."); return; } //to check the data in excel for (int i = 0; i < ds.Tables[0].Rows.Count; i++) { errormsg = string.Empty; columnno = string.Empty; if (ds.Tables[0].Rows[i]["Name*"].ToString().Trim() != "") { _obj_Smhr_Category = new SMHR_CATEGORY(); _obj_Smhr_Category.CATEGORY_CODE = Convert.ToString(ds.Tables[0].Rows[i]["Name*"]).Trim(); _obj_Smhr_Category.ORGANISATION_ID = Convert.ToInt32(Session["ORG_ID"]); _obj_Smhr_Category.OPERATION = operation.Check; if (Convert.ToString(BLL.get_Category(_obj_Smhr_Category).Rows[0]["Count"]) != "0") { // BLL.ShowMessage(this, "Category with this Name Already Exists"); // return; errormsg = "Category with this Name Already Exists"; filestatus = false; rowno = i + 2; columnno = "Name*"; } } else { filestatus = false; rowno = i + 2; columnno = "Name*"; } for (int k = 0; k < ds.Tables[0].Rows.Count; k++) { if (ds.Tables[0].Rows[i]["Name*"].ToString().Trim() == ds.Tables[0].Rows[k]["Name*"].ToString().Trim()) { if (i != k) { errormsg = "Category with this Name is repeated in Excel Sheet"; filestatus = false; rowno = i + 2; columnno = "Name*"; } } } if (ds.Tables[0].Rows[i]["Description"].ToString().Trim() != "") { } else { filestatus = false; rowno = i + 2; columnno = columnno + "," + "Description"; } if (ds.Tables[0].Rows[i]["OverTime Enabled"].ToString().Trim() != "") { } else { filestatus = false; rowno = i + 2; columnno = columnno + "," + "OverTime Enabled"; } if (ds.Tables[0].Rows[i]["Bank Info"].ToString().Trim() != "") { } else { filestatus = false; rowno = i + 2; columnno = columnno + "," + "Bank Info"; } if (ds.Tables[0].Rows[i]["Currency"].ToString().Trim() != "") { } else { filestatus = false; rowno = i + 2; columnno = columnno + "," + "Currency"; } if (ds.Tables[0].Rows[i]["Age"].ToString().Trim() != "") { } else { filestatus = false; rowno = i + 2; columnno = columnno + "," + "Age"; } if (ds.Tables[0].Rows[i]["DateFormat"].ToString().Trim() != "") { } else { filestatus = false; rowno = i + 2; columnno = columnno + "," + "DateFormat"; } if (ds.Tables[0].Rows[i]["Address"].ToString().Trim() != "") { } else { filestatus = false; rowno = i + 2; columnno = columnno + "," + "Address"; } if (ds.Tables[0].Rows[i]["Country"].ToString().Trim() != "") { } else { filestatus = false; rowno = i + 2; columnno = columnno + "," + "Country"; } if (ds.Tables[0].Rows[i]["Fiscal Year"].ToString().Trim() != "") { } else { filestatus = false; rowno = i + 2; columnno = columnno + "," + "Fiscal Year"; } if (ds.Tables[0].Rows[i]["Calendar"].ToString().Trim() != "") { } else { filestatus = false; rowno = i + 2; columnno = columnno + "," + "Calendar"; } if (ds.Tables[0].Rows[i]["Payment Methods"].ToString().Trim() != "") { } else { filestatus = false; rowno = i + 2; columnno = columnno + "," + "Payment Methods"; } if (ds.Tables[0].Rows[i]["Localisation"].ToString().Trim() != "") { } else { filestatus = false; rowno = i + 2; columnno = columnno + "," + "Localisation"; } if (filestatus == false) { DataRow newrow = dtfail.NewRow(); newrow["S.NO"] = dtfail.Rows.Count + 1; newrow["ROWNO"] = rowno; newrow["COLUMNS NAMES"] = columnno; dtfail.Rows.Add(newrow); ds.Tables[0].Rows[i]["Error Message"] = errormsg; } } if (dtfail.Rows.Count > 0) { Session["dt_fail"] = dtfail; Session["ds_data"] = ds; Delete_Excel_File(); //LinkButton lnk_Import_process = (LinkButton)RadPanelBar1.FindItemByValue("AddAttachment").FindControl("lnk_Import_process"); Telerik.Web.UI.RadWindow newwindow = new Telerik.Web.UI.RadWindow(); // RWM_POSTREPLY.Windows.Remove(newwindow); newwindow.ID = "RadWindow_import"; newwindow.NavigateUrl = "~/Payroll/frm_AttendanceImportProcess.aspx"; newwindow.Title = "Import Process"; newwindow.Width = 1150; newwindow.Height = 580; newwindow.VisibleOnPageLoad = true; if (RWM_POSTREPLY1.Windows.Count > 1) { RWM_POSTREPLY1.Windows.RemoveAt(1); } RWM_POSTREPLY1.Windows.Add(newwindow); RWM_POSTREPLY1.Visible = true; return; } else { for (int i = 0; i < ds.Tables[0].Rows.Count; i++) { bool status = false; _obj_Smhr_Category.CATEGORY_CODE = Convert.ToString(ds.Tables[0].Rows[i]["Name*"]).Trim(); _obj_Smhr_Category.CATEGORY_DESC = Convert.ToString(ds.Tables[0].Rows[i]["Description"]).Trim(); _obj_Smhr_Category.CATEGORY_ISOVERTIME = Convert.ToBoolean(ds.Tables[0].Rows[i]["OverTime Enabled"]); _obj_Smhr_Category.CATEGORY_NEEDBANKINFO = Convert.ToBoolean(ds.Tables[0].Rows[i]["Bank Info"]); _obj_Smhr_Category.ORGANISATION_ID = Convert.ToInt32(Session["ORG_ID"]); _obj_Smhr_Category.CATEGORY_ISFISCALYEAR = Convert.ToBoolean(ds.Tables[0].Rows[i]["Fiscal Year"]); _obj_Smhr_Category.CATEGORY_ISCURRENCY = Convert.ToBoolean(ds.Tables[0].Rows[i]["Currency"]); _obj_Smhr_Category.CATEGORY_ISDATEFORMAT = Convert.ToBoolean(ds.Tables[0].Rows[i]["DateFormat"]); _obj_Smhr_Category.CATEGORY_ISCOUNTRY = Convert.ToBoolean(ds.Tables[0].Rows[i]["Country"]); _obj_Smhr_Category.CATEGORY_ISADDRESS = Convert.ToBoolean(ds.Tables[0].Rows[i]["Address"]); _obj_Smhr_Category.CATEGORY_ISAGE = Convert.ToBoolean(ds.Tables[0].Rows[i]["Age"]); _obj_Smhr_Category.CATEGORY_ISPAYMENTMODE = Convert.ToBoolean(ds.Tables[0].Rows[i]["Payment Methods"]); _obj_Smhr_Category.CATEGORY_ISCALENDERYEAR = Convert.ToBoolean(ds.Tables[0].Rows[i]["Calendar"]); _obj_Smhr_Category.CATEGORY_LOCALISATION = Convert.ToBoolean(ds.Tables[0].Rows[i]["Localisation"]); _obj_Smhr_Category.CREATEDBY = Convert.ToInt32(Session["USER_ID"]); // ### Need to Get the Session _obj_Smhr_Category.CREATEDDATE = DateTime.Now; _obj_Smhr_Category.LASTMDFBY = Convert.ToInt32(Session["USER_ID"]); // ### Need to Get the Session _obj_Smhr_Category.LASTMDFDATE = DateTime.Now; _obj_Smhr_Category.ORGANISATION_ID = Convert.ToInt32(Session["ORG_ID"]); _obj_Smhr_Category.OPERATION = operation.Insert; status = BLL.set_Category(_obj_Smhr_Category); if (status == true) { BLL.ShowMessage(this, "Information Saved Successfully"); } ////else //// BLL.ShowMessage(this, "Information Not Saved"); } LoadGrid(); Rg_Categories.DataBind(); } } catch (Exception ex) { SMHR.BLL.Error_Log(Session["USER_ID"].ToString(), ex.TargetSite.ToString(), ex.Message.Replace("'", "''"), "frm_Catagory", ex.StackTrace, DateTime.Now); Response.Redirect("~/Frm_ErrorPage.aspx"); } }