예제 #1
0
        /// <summary>
        /// Process Names (ATTD,MESS,LUNCHINOUT) GLOBAL VAR OF FORM
        /// Process Mode (APP,SERVER) -> Kind of Process wether application side , server side
        /// ProcessType (EMP,WRKGRP) -> Employee Wise or WrkGrp Wise
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        /// <param name="ProcessMode">APP/SERVER</param>
        /// <param name="ProcessType">EMP/WRKGRP</param>
        private void ProcessDATA(object sender, EventArgs e, string tProcessMode = "APP", string tProcessType = "EMP")
        {
            if (ProcessList.Rows.Count <= 0)
            {
                MessageBox.Show("No Records found to process..", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            btnAdd.Enabled           = false;
            btnDelete.Enabled        = false;
            btnClearList.Enabled     = false;
            btnProcessWrkGrp.Enabled = false;
            txtWrkFromDt.Enabled     = false;
            txtWrkToDate.Enabled     = false;
            txtWrkGrpCode.Enabled    = false;

            ISProcessStarted = true;
            appstatus_Tick(sender, e);


            Cursor.Current = Cursors.WaitCursor;

            clsProcess pr = new clsProcess();

            if (ProcessName == "ATTD")
            {
                foreach (DataRow dr in ProcessList.Rows)
                {
                    string   tEmpUnqID = dr["EmpUnqID"].ToString();
                    DateTime tFromDt   = Convert.ToDateTime(dr["FromDate"]);
                    DateTime tToDt     = Convert.ToDateTime(dr["ToDate"]);
                    int      res;
                    string   proerr = string.Empty;
                    pr.AttdProcess(tEmpUnqID, tFromDt, tToDt, out res, out proerr);

                    //update processed status
                    if (res > 0)
                    {
                        dr.BeginEdit();
                        dr["IsDone"] = 1;
                        dr["Status"] = "Processed";
                        dr.EndEdit();
                        dr.AcceptChanges();
                        RefreshAppGrid(sender, e);
                        Application.DoEvents();
                    }

                    if (!string.IsNullOrEmpty(proerr))
                    {
                        dr["Status"] = "Processed but with error : " + proerr;
                    }
                }
            }
            else if (ProcessName == "MESS")
            {
                foreach (DataRow dr in ProcessList.Rows)
                {
                    string   tEmpUnqID = dr["EmpUnqID"].ToString();
                    DateTime tFromDt   = Convert.ToDateTime(dr["FromDate"]);
                    DateTime tToDt     = Convert.ToDateTime(dr["ToDate"]);
                    int      res;
                    pr.LunchProcess(tEmpUnqID, tFromDt, tToDt, out res);
                    Application.DoEvents();
                    //update processed status
                    if (res > 0)
                    {
                        dr.BeginEdit();
                        dr["IsDone"] = 1;
                        dr["Status"] = "Processed";
                        dr.EndEdit();
                        dr.AcceptChanges();
                        RefreshAppGrid(sender, e);
                    }
                }
            }
            else if (ProcessName == "LUNCHINOUT")
            {
                foreach (DataRow dr in ProcessList.Rows)
                {
                    string   tEmpUnqID = dr["EmpUnqID"].ToString();
                    DateTime tFromDt   = Convert.ToDateTime(dr["FromDate"]);
                    DateTime tToDt     = Convert.ToDateTime(dr["ToDate"]);
                    int      res;
                    pr.LunchInOutProcess(tEmpUnqID, tFromDt, tToDt, out res);
                    Application.DoEvents();
                    //update processed status
                    if (res > 0)
                    {
                        dr.BeginEdit();
                        dr["IsDone"] = 1;
                        dr["Status"] = "Processed";
                        dr.EndEdit();
                        dr.AcceptChanges();
                        RefreshAppGrid(sender, e);
                    }
                }
            }

            Cursor.Current           = Cursors.Default;
            btnAdd.Enabled           = true;
            btnDelete.Enabled        = true;
            btnProcessWrkGrp.Enabled = true;
            txtWrkFromDt.Enabled     = true;
            txtWrkToDate.Enabled     = true;
            txtWrkGrpCode.Enabled    = true;

            btnClearList.Enabled = true;
            ISProcessStarted     = false;
            appstatus_Tick(sender, e);
            MessageBox.Show("Process Completed...", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
예제 #2
0
        private void btnImport_Click(object sender, EventArgs e)
        {
            Cursor.Current = Cursors.WaitCursor;
            DataTable LunchMachines = Utils.Helper.GetData("Select * from [LunchMachine]", Utils.Helper.constr).Tables[0];
            DataTable dtMaterial    = new DataTable();
            DataTable sortedDT      = new DataTable();

            try
            {
                foreach (GridColumn column in grd_view1.VisibleColumns)
                {
                    if (column.FieldName != string.Empty)
                    {
                        dtMaterial.Columns.Add(column.FieldName, column.ColumnType);
                    }
                }


                for (int i = 0; i < grd_view1.DataRowCount; i++)
                {
                    DataRow row = dtMaterial.NewRow();

                    foreach (GridColumn column in grd_view1.VisibleColumns)
                    {
                        row[column.FieldName] = grd_view1.GetRowCellValue(i, column);
                    }
                    dtMaterial.Rows.Add(row);
                }

                DataView dv = dtMaterial.DefaultView;
                dv.Sort  = "EmpUnqID asc";
                sortedDT = dv.ToTable();

                using (SqlConnection con = new SqlConnection(Utils.Helper.constr))
                {
                    DateTime tdt;

                    con.Open();
                    foreach (DataRow dr in sortedDT.Rows)
                    {
                        string tEmpUnqID = dr["EmpUnqID"].ToString();


                        try
                        {
                            tdt = Convert.ToDateTime(dr["SanDate"]);
                        }
                        catch (Exception ex)
                        {
                            dr["Remarks"] = "Sanction Date Conversion failed...";
                            continue;
                        }

                        string err = DataValidate(dr);

                        if (!string.IsNullOrEmpty(err))
                        {
                            dr["Remarks"] = err;
                            continue;
                        }

                        if (string.IsNullOrEmpty(dr["Location"].ToString().Trim()))
                        {
                            dr["Remarks"] = "Location Must be Required..";
                            continue;
                        }

                        clsEmp Emp = new clsEmp();

                        #region Chk_Primary

                        try
                        {
                            Emp.CompCode = "01";
                            Emp.EmpUnqID = tEmpUnqID;
                            Emp.GetEmpDetails(Emp.CompCode, Emp.EmpUnqID);
                        }
                        catch (Exception ex)
                        {
                            dr["Remarks"] = ex.ToString();
                            continue;
                        }
                        #endregion

                        #region Chk_AllVals
                        //check all values if all empty skip
                        if (dr["LunchTime"].ToString().Trim() == "")
                        {
                            dr["Remarks"] = dr["Remarks"].ToString() + " Nothing to update...";
                            continue;
                        }
                        #endregion

                        DateTime tInTime = new DateTime(), tDate = new DateTime();
                        DateTime tSanDate = Convert.ToDateTime(dr["SanDate"]).Date;
                        #region Chk_InTime
                        if (dr["LunchTime"].ToString().Trim() != "" && dr["SanDate"] != DBNull.Value)
                        {
                            tInTime = Convert.ToDateTime(dr["SanDate"]);
                            string[] inary = dr["LunchTime"].ToString().Split(':');

                            if (inary.GetLength(0) >= 2)
                            {
                                tInTime = tInTime.AddHours(Convert.ToInt32(inary[0].ToString().Trim()));
                                tInTime = tInTime.AddMinutes(Convert.ToInt32(inary[1].ToString().Trim()));
                            }
                            else
                            {
                                dr["LunchTime"] = DBNull.Value;
                                dr["Remarks"]   = dr["Remarks"].ToString() + " Invalid InTime, will not be considered..";
                                continue;
                            }
                        }
                        #endregion


                        #region Chk_AllVals
                        //check all values if all empty skip
                        if (dr["LunchTime"].ToString().Trim() == "")
                        {
                            dr["Remarks"] = dr["Remarks"].ToString() + " Nothing to update...";
                            continue;
                        }

                        string sWrkGrp = "", sDate = "", sInTime = "", sLocation = "", sInMachine = "";

                        sWrkGrp = Emp.WrkGrp;

                        sLocation = dr["Location"].ToString().Trim();


                        string expression;
                        expression = "Location = '" + sLocation + "'";
                        DataRow[] foundRows;
                        foundRows = LunchMachines.Select(expression);
                        if (foundRows.Length <= 0)
                        {
                            dr["Remarks"] = dr["Remarks"].ToString() + " Invalid Location...";
                            continue;
                        }
                        else
                        {
                            sInMachine = foundRows[0]["InMachine"].ToString();
                        }

                        #endregion


                        #region Set_InTime
                        if (tInTime == DateTime.MinValue || tInTime == Convert.ToDateTime(dr["SanDate"]))
                        {
                            sInTime = " NULL ";
                        }
                        else if (tInTime.Hour > 0 || tInTime.Minute >= 0)
                        {
                            sInTime = "'" + tInTime.ToString("yyyy-MM-dd HH:mm:ss") + "'";
                        }
                        else
                        {
                            sInTime = " NULL ";
                        }
                        #endregion



                        #region Final_Update


                        string sql = string.Empty;


                        using (SqlCommand cmd = new SqlCommand())
                        {
                            try
                            {
                                sDate = Convert.ToDateTime(dr["SanDate"]).ToString("yyyy-MM-dd");
                                tDate = Convert.ToDateTime(dr["SanDate"]);
                                sql   = string.Empty;

                                cmd.Connection  = con;
                                cmd.CommandType = CommandType.Text;
                                if (!string.IsNullOrEmpty(sInTime) && sInTime != " NULL ")
                                {
                                    sql = "Insert Into AttdLog " +
                                          " (PunchDate,EmpUnqID,IOFLG,MachineIP,LunchFlg,tYear,tYearMt,t1Date,AddDt,AddID) Values (" +
                                          " " + sInTime + ",'" + Emp.EmpUnqID + "','B','" + sInMachine + "',1,'" + tDate.Year + "','" + tDate.ToString("yyyyMM") + "','" + sDate + "',GetDate(),'" + Utils.User.GUserID + "-San" + "')";
                                }

                                cmd.CommandText    = sql;
                                cmd.CommandTimeout = 0;
                                cmd.ExecuteNonQuery();



                                clsProcess pro    = new clsProcess();
                                int        result = 0;
                                string     proerr = string.Empty;
                                pro.LunchProcess(Emp.EmpUnqID, tDate, tDate.AddDays(1), out result);
                                dr["remarks"] = dr["remarks"].ToString() + "Record updated...";
                            }
                            catch (Exception ex)
                            {
                                dr["remarks"] = dr["remarks"].ToString() + ex.ToString();
                                continue;
                            }
                        } //using sqlcommand
                        #endregion
                    }     //using foreach

                    con.Close();
                }//using connection

                Cursor.Current = Cursors.Default;
                MessageBox.Show("file uploaded Successfully, please check the remarks for indivisual record status...", "Info", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            catch (Exception ex) { MessageBox.Show(ex.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); }
            DataSet ds = new DataSet();
            ds.Tables.Add(sortedDT);
            grd_view.DataSource = ds;
            grd_view.DataMember = ds.Tables[0].TableName;
            grd_view.Refresh();

            Cursor.Current = Cursors.Default;
        }