Exemplo n.º 1
0
    public string SaveProduction(DataTable dt)
    {
        string lblMessage = "";
        ProductionController objCont = new ProductionController();

        DataTable dtView = new DataTable();
        string strViewQuery = "Select distinct * from vwMastersCode";
        dtView = objQueryController.ExecuteQuery(strViewQuery);

        DataTable dtModel = new DataTable();
        string strModelQuery = "select * from Model";
        dtModel = objQueryController.ExecuteQuery(strModelQuery);

                string sConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings["connectionString"].ToString();

                //try
                //{
                //    string strDelete = "Delete from ProductionTemp";
                //    objController.ExecuteQuery(strDelete);

                //    SqlConnection sqlconn = new SqlConnection(sConnectionString);
                //    sqlconn.Open();
                //    SqlBulkCopy bulkCopy = new SqlBulkCopy(sqlconn);
                //    bulkCopy.DestinationTableName = "ProductionTemp";
                //    bulkCopy.WriteToServer(dt);

                //}
                //catch
                //{

                //}
                int rcount = 0;
                foreach (DataRow dr in dt.Rows)
                {
                    ProductionUI objUI = new ProductionUI();
                    string strCause = "model";
                    int modelex = 1;

                    try
                    {
                        int flag = 0;
                        for (int i = 0; i < dtView.Rows.Count; i++)
                        {
                            if ("model" == dtView.Rows[i]["tablename"].ToString() && dr["Model_Code"].ToString() == dtView.Rows[i]["code"].ToString())
                            {
                                DataView dv = new DataView(dtModel);
                                dv.RowFilter = "Code ='" + dr["Model_Code"].ToString() + "'";
                                DataTable dtModelCode = dv.ToTable();
                                objUI.Model_Code = Convert.ToString(dtModelCode.Rows[0]["Model_Code"]);
                                strCause = strCause.Replace("model", "");
                                modelex = 0;
                                flag++;
                            }
                        }
                        string strS = Convert.ToString(dr["S"]);
                        if (strS == "")
                        {
                            objUI.S = Convert.ToInt32(null);
                        }
                        else
                        {
                            objUI.S = Convert.ToInt32(dr["S"]);
                        }

                        objUI.Material = Convert.ToString(dr["Material"]);
                        objUI.SerialNo = Convert.ToString(dr["Serial no#"]);
                        objUI.Plnt = Convert.ToString(dr["Plnt"]);

                        string strSLoc = Convert.ToString(dr["SLoc"]);
                        if (strSLoc == "")
                        {
                            objUI.SLoc = Convert.ToString(null);
                        }
                        else
                        {
                            objUI.SLoc = Convert.ToString(dr["SLoc"]);
                        }
                        objUI.Description = Convert.ToString(dr["Description of technical object"]);
                        objUI.Production_Month = Convert.ToInt16(dr["Production_Month"]);
                        objUI.Production_Month_Year = Convert.ToString(dr["Production_Month_Year"]);
                        objUI.FromDate = Convert.ToDateTime(dr["FromDate"]);
                        objUI.ToDate = Convert.ToDateTime(dr["ToDate"]);
                        objUI.MonthID = Convert.ToInt16(dr["MonthID"]);
                        objUI.YearID = Convert.ToInt16(dr["YearID"]);
                        objUI.Quarter = Convert.ToString(dr["Quarter"]);

                        if (flag == 1)
                        {
                            objCont.SaveProduction(objUI);
                            rcount++;
                        }
                        else
                        {

                            string strQuery = "Insert into ProductionTemp ([S],[Material],[Serial no#],[Plnt],[SLoc],[Description of technical object],[Production_Month],[Model_Code],[Production_Month_Year],[IsApproved],MonthID,YearID,[Quarter],IsModelEx) ";
                            strQuery += "Values ('" + dr["S"].ToString() + "','" + dr["Material"].ToString() + "','" + dr["Serial no#"].ToString() + "','" + dr["Plnt"].ToString() + "','" + dr["SLoc"].ToString() + "','" + dr["Description of technical object"].ToString() + "','" + dr["Production_Month"].ToString() + "','" + dr["Model_Code"].ToString() + "','" + dr["Production_Month_Year"].ToString() + "',0,'" + dr["MonthID"].ToString() + "','" + dr["YearID"].ToString() + "','" + dr["Quarter"].ToString() + "','" + modelex + "')";
                            objQueryController.ExecuteQuery(strQuery);
                        }
                        lblMessage = "File Production saved successfully;No of Rows Affected:" + rcount;
                    }
                    catch
                    {

                        string strQuery = "Insert into ProductionTemp ([S],[Material],[Serial no#],[Plnt],[SLoc],[Description of technical object],[Production_Month],[Model_Code],[Production_Month_Year],[IsApproved],MonthID,YearID,[Quarter],IsModelEx) ";
                        strQuery += "Values ('" + dr["S"].ToString() + "','" + dr["Material"].ToString() + "','" + dr["Serial no#"].ToString() + "','" + dr["Plnt"].ToString() + "','" + dr["SLoc"].ToString() + "','" + dr["Description of technical object"].ToString() + "','" + dr["Production_Month"].ToString() + "','" + dr["Model_Code"].ToString() + "','" + dr["Production_Month_Year"].ToString() + "',0,'" + dr["MonthID"].ToString() + "','" + dr["YearID"].ToString() + "','" + dr["Quarter"].ToString() + "','" + modelex + "')";
                        objQueryController.ExecuteQuery(strQuery);
                    }

                }
        return lblMessage;
    }
Exemplo n.º 2
0
    /***********************************Function to Production Acr File into Sql Server 2000 using Bulk Copy Method***********************************/
    public string SaveProduction(DataTable dt)
    {
        string lblMessage = "";
        ProductionController objCont = new ProductionController();

        DataTable dtView = new DataTable();
        string strViewQuery = "Select distinct * from vwMastersCode";
        dtView = objController.ExecuteQuery(strViewQuery);

        //DataTable dtModel = new DataTable();
        //string strModelQuery = "select * from Model";
        //dtModel = objController.ExecuteQuery(strModelQuery);

        DataTable dtMonthOC = new DataTable();
        string strMonthOCQuery = "select * from MonthOpenClose";
        dtMonthOC = objController.ExecuteQuery(strMonthOCQuery);
        DataView dvMonthOC = new DataView(dtMonthOC);
        DataTable dtFilter = new DataTable();
        string[] strProdFromMonth = txtProdFromDate.Text.Trim().Split('/');
        int FromMonth = Convert.ToInt16(strProdFromMonth[1]);
        //int FromMonth = CalProdfromDate.SelectedDate.Month;
        dvMonthOC.RowFilter = "MonthID =" + FromMonth;
        dtFilter = dvMonthOC.ToTable();

        if (dtFilter.Rows != null)
        {
            bool OCStatus = Convert.ToBoolean(dtFilter.Rows[0]["Status"]);

            if (OCStatus == false)
            {
                lblMessage = "Month is Closed, Please open month to enter data";
            }
            else
            {
                //int ToMonth = CalProdtoDate.SelectedDate.Month;
                string[] strToProdMonth = txtProdToDate.Text.Trim().Split('/');
                int ToMonth = Convert.ToInt16(strToProdMonth[1]);
                string sConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings["connectionString"].ToString();

                //try
                //{
                //    string strDelete = "Delete from ProductionTemp";
                //    objController.ExecuteQuery(strDelete);

                //    SqlConnection sqlconn = new SqlConnection(sConnectionString);
                //    sqlconn.Open();
                //    SqlBulkCopy bulkCopy = new SqlBulkCopy(sqlconn);
                //    bulkCopy.DestinationTableName = "ProductionTemp";
                //    bulkCopy.WriteToServer(dt);

                //}
                //catch
                //{

                //}
                int rcount = 0;
                foreach (DataRow dr in dt.Rows)
                {
                    ProductionUI objUI = new ProductionUI();
                    string strCause = "model";
                    int modelex = 1;

                    try
                    {
                        int flag = 0;
                        //for (int i = 0; i < dtView.Rows.Count; i++)
                        //{
                        //    if ("model" == dtView.Rows[i]["tablename"].ToString() && dr["Model_Code"].ToString() == dtView.Rows[i]["code"].ToString())
                        //    {
                        //        DataView dv = new DataView(dtModel);
                        //        dv.RowFilter = "Code ='" + dr["Model_Code"].ToString() + "'";
                        //        DataTable dtModelCode = dv.ToTable();
                        //        objUI.Model_Code = Convert.ToString(dtModelCode.Rows[0]["Model_Code"]);
                        //        strCause = strCause.Replace("model", "");
                        //        modelex = 0;
                        //        flag++;
                        //    }
                        //}
                        string strMaterial = Convert.ToString(dr["Material"]);
                          string strModelQuery = "Select * from ModelMapping where Material='" + strMaterial + "'";
                        DataTable dtModel = objController.ExecuteQuery(strModelQuery);
                        if (dtModel != null)
                        {
                            if (dtModel.Rows.Count > 0)
                            {
                                foreach (DataRow drModel in dtModel.Rows)
                                {
                                    objUI.ModelMappingID = Convert.ToInt32(drModel["ID"].ToString());
                                    strCause = strCause.Replace("model", "");
                                    modelex = 0;
                                    flag++;
                                }
                            }
                        }
                        string strS = Convert.ToString(dr["S"]);
                        if (strS == "")
                        {
                            objUI.S = Convert.ToInt16(null);
                        }
                        else
                        {
                            objUI.S = Convert.ToInt16(dr["S"]);
                        }

                        objUI.Material = Convert.ToString(dr["Material"]);

                        objUI.SerialNo = Convert.ToString(dr["Serial no."]);
                        objUI.Plnt = Convert.ToString(dr["Plnt"]);

                        objUI.SLoc = Convert.ToString(dr["SLoc"]);

                        objUI.Description = Convert.ToString(dr["Description of technical object"]);
                        objUI.Production_Month = Convert.ToInt16(dr["Production_Month"]);
                        objUI.Production_Month_Year = Convert.ToString(dr["Production_Month_Year"]);
                        //objUI.FromDate = CalProdfromDate.SelectedDate;
                        //objUI.ToDate = CalProdtoDate.SelectedDate;
                        objUI.FromDate = Convert.ToDateTime(objUtility.ConvertDateTime(txtProdFromDate.Text.Trim()));
                        objUI.ToDate = Convert.ToDateTime(objUtility.ConvertDateTime(txtProdToDate.Text.Trim()));
                        objUI.MonthID = Convert.ToInt16(dr["MonthID"]);
                        objUI.YearID = Convert.ToInt16(dr["YearID"]);
                        objUI.Quarter = Convert.ToString(dr["Quarter"]);

                        if (flag == 1)
                        {
                            objCont.SaveProduction(objUI);
                            rcount++;
                        }
                        else
                        {
                            lnkProdException.Visible = true;
                            string strQuery = "Insert into ProductionTemp ([S],[Material],[Serial no#],[Plnt],[SLoc],[Description of technical object],[Production_Month],[Model_Code],[Production_Month_Year],[IsApproved],MonthID,YearID,[Quarter],IsModelEx,FromDate,ToDate) ";
                            strQuery += "Values ('" + dr["S"].ToString() + "','" + dr["Material"].ToString() + "','" + dr["Serial no."].ToString() + "','" + dr["Plnt"].ToString() + "','" + dr["SLoc"].ToString() + "','" + dr["Description of technical object"].ToString() + "','" + dr["Production_Month"].ToString() + "','" + dr["Model_Code"].ToString() + "','" + dr["Production_Month_Year"].ToString() + "',0,'" + dr["MonthID"].ToString() + "','" + dr["YearID"].ToString() + "','" + dr["Quarter"].ToString() + "','" + modelex + "','" + objUtility.ConvertDateTime(txtProdFromDate.Text.Trim()) + "','" + objUtility.ConvertDateTime(txtProdToDate.Text.Trim()) + "')";
                            objController.ExecuteQuery(strQuery);
                        }
                        lblMessage = "File Production saved successfully;No of Rows Affected:" + rcount;
                    }
                    catch
                    {
                        lnkProdException.Visible = true;
                        string strQuery = "Insert into ProductionTemp ([S],[Material],[Serial no#],[Plnt],[SLoc],[Description of technical object],[Production_Month],[Model_Code],[Production_Month_Year],[IsApproved],MonthID,YearID,[Quarter],IsModelEx,FromDate,ToDate) ";
                        strQuery += "Values ('" + dr["S"].ToString() + "','" + dr["Material"].ToString() + "','" + dr["Serial no."].ToString() + "','" + dr["Plnt"].ToString() + "','" + dr["SLoc"].ToString() + "','" + dr["Description of technical object"].ToString() + "','" + dr["Production_Month"].ToString() + "','" + dr["Model_Code"].ToString() + "','" + dr["Production_Month_Year"].ToString() + "',0,'" + dr["MonthID"].ToString() + "','" + dr["YearID"].ToString() + "','" + dr["Quarter"].ToString() + "','" + modelex + "','" + objUtility.ConvertDateTime(txtProdFromDate.Text.Trim()) + "','" + objUtility.ConvertDateTime(txtProdToDate.Text.Trim()) + "')";
                        objController.ExecuteQuery(strQuery);
                    }

                }
                //string strAcrUpdateQuery = "UPDATE AcrBulk SET ModelMappingID =( SELECT Production.ModelMappingID FROM Production WHERE Production.SerialNo = Convert(varchar,AcrBulk.Tractor_No)) WHERE EXISTS ( SELECT Production.ModelMappingID FROM Production WHERE Production.SerialNo = Convert(varchar,AcrBulk.Tractor_No))";
                string strAcrUpdateQuery = "Update AcrBulk set ModelMappingID = Production.ModelMappingID  from AcrBulk inner join Production on Convert(varchar,AcrBulk.Tractor_No) = Production.SerialNo ";
                objController.ExecuteQuery(strAcrUpdateQuery);

            }
        }
        return lblMessage;
    }
    protected void btnUpdate_Click(object sender, EventArgs e)
    {
        DataTable dtProdMonth = new DataTable();
        string strProdMonthQuery = "select * from ProductionMonth";
        dtProdMonth = objQueryController.ExecuteQuery(strProdMonthQuery);

        DataTable dtView = new DataTable();
        string strViewQuery = "Select distinct * from vwMastersCode";
        dtView = objQueryController.ExecuteQuery(strViewQuery);

        //DataTable dtModel = new DataTable();
        //string strModelQuery = "select * from Model";
        //dtModel = objQueryController.ExecuteQuery(strModelQuery);
        ProductionController objCont = new ProductionController();

        int rcount = 0;
        foreach (GridViewRow gr in grdProdException.Rows)
        {
            bool Discard = ((CheckBox)gr.FindControl("chkDiscard")).Checked;
            string str = ((HiddenField)gr.FindControl("hdnID")).Value;
            if (Discard == true)
            {
                string strDiscardQuery = "Delete from ProductionTemp where ID=" + Convert.ToInt16(str);
                objQueryController.ExecuteQuery(strDiscardQuery);

                string strQuery = "Select * from Productiontemp";
                DataTable dt = new DataTable();
                dt = objQueryController.ExecuteQuery(strQuery);

                grdProdException.DataSource = dt;
                grdProdException.DataBind();
            }
            else
            {

                ProductionUI objUI = new ProductionUI();
                int CurrentYearID = 0;
                int CurrentMonthID = 0;
                string strProductionMonthYear = "";
                int modelex=1;
                string strQuarterYear = "";
                string ProductionMonth = "";
                try
                {
                    string strS = Convert.ToString(((TextBox)gr.FindControl("txtS")).Text);
                    if (strS == "")
                    {
                        objUI.S = Convert.ToInt32(null);
                    }
                    else
                    {
                        objUI.S = Convert.ToInt32(((TextBox)gr.FindControl("txtS")).Text);
                    }

                    objUI.Material = Convert.ToString(((TextBox)gr.FindControl("txtMaterial")).Text);
                    objUI.SerialNo = Convert.ToString(((TextBox)gr.FindControl("txtSerialNo")).Text.Trim());
                    objUI.Plnt = Convert.ToString(((TextBox)gr.FindControl("txtPlnt")).Text);

                    string strSLoc = Convert.ToString(((TextBox)gr.FindControl("txtSLoc")).Text);
                    if (strSLoc == "")
                    {
                        objUI.SLoc = Convert.ToString(null);
                    }
                    else
                    {
                        objUI.SLoc = Convert.ToString(((TextBox)gr.FindControl("txtSLoc")).Text);
                    }
                    objUI.Description = Convert.ToString(((TextBox)gr.FindControl("txtDescription")).Text);

                    string strSerialNo = Convert.ToString(((TextBox)gr.FindControl("txtSerialNo")).Text.Trim());
                    int serialnoLength = strSerialNo.Length;

                    string ModelCode = "0";

                    if (serialnoLength == 11)                            //If Tractor No Length is 11
                    {
                        ProductionMonth = strSerialNo.Substring(1, 2);   // 2nd and 3rd digit is Production Month
                        ModelCode = strSerialNo.Substring(3, 3);         // The next 3 digits i.e. 4th, 5th and 6th digits is Model Code
                    }
                    else if (serialnoLength == 12)                       //If Tractor No Length is 12
                    {
                        ProductionMonth = strSerialNo.Substring(1, 3);   // 2nd to 4th digit is Production Month
                        ModelCode = strSerialNo.Substring(4, 3);         // The next 3 digits i.e. 5th, 6th and 7th digits is Model Code
                    }

                    //DataView dv = new DataView(dtModel);
                    //dv.RowFilter = "Code =" + Convert.ToInt16(ModelCode);
                    //DataTable dtModelCode = dv.ToTable();
                    //objUI.Production_Month = Convert.ToInt16(ProductionMonth);
                    //try
                    //{
                    //    objUI.Model_Code = Convert.ToString(dtModelCode.Rows[0]["Model_Code"]);
                    //}
                    //catch
                    //{

                    //}
                    int flag = 0;
                    //for (int i = 0; i < dtView.Rows.Count; i++)
                    //{
                    //    if ("model" == dtView.Rows[i]["tablename"].ToString() && Convert.ToString(ModelCode) == dtView.Rows[i]["code"].ToString())
                    //    {
                    //        DataView dv = new DataView(dtModel);
                    //        dv.RowFilter = "Code ='" + Convert.ToString(ModelCode) + "'";
                    //        DataTable dtModelCode = dv.ToTable();
                    //        objUI.Model_Code = Convert.ToString(dtModelCode.Rows[0]["Model_Code"]);
                    //        //strCause = strCause.Replace("model", "");
                    //        //modelex = 0;
                    //        flag++;
                    //    }
                    //}
                    string strMaterial = Convert.ToString(((TextBox)gr.FindControl("txtMaterial")).Text);
                    string strModelQuery = "Select * from ModelMapping where Material='" + strMaterial + "'";
                    DataTable dtModel = objQueryController.ExecuteQuery(strModelQuery);
                    if (dtModel != null)
                    {
                        if (dtModel.Rows.Count > 0)
                        {
                            foreach (DataRow drModel in dtModel.Rows)
                            {
                                objUI.ModelMappingID = Convert.ToInt32(drModel["ID"].ToString());
                                //strCause = strCause.Replace("model", "");
                                modelex = 0;
                                flag++;
                            }
                        }
                    }

                    if (ProductionMonth != "")
                    {
                        int BaseProductionMonth = Convert.ToInt16(dtProdMonth.Rows[0]["BaseProductionMonth_Code"]);
                        int BaseMonthID = Convert.ToInt16(dtProdMonth.Rows[0]["Month_ID"]);
                        int BaseYearID = Convert.ToInt16(dtProdMonth.Rows[0]["Year_ID"]);

                        string strBaseDate = Convert.ToString(BaseMonthID) + "/1/" + BaseYearID;
                        DateTime BaseDate = Convert.ToDateTime(strBaseDate);
                        int Offset = Convert.ToInt16(ProductionMonth) - BaseProductionMonth;
                        DateTime ProdMonthYear = BaseDate.AddMonths(Offset);

                        CurrentYearID = ProdMonthYear.Year;
                        CurrentMonthID = ProdMonthYear.Month;

                        string strCurrentYearID = (Convert.ToString(CurrentYearID)).Substring(2, 2);

                        string strMonth = getMonth(CurrentMonthID);

                        strProductionMonthYear = strMonth + "-" + strCurrentYearID;

                        objUI.MonthID = CurrentMonthID;
                        objUI.YearID = CurrentYearID;
                        string strQuarter = "";

                        if (CurrentMonthID == 4 || CurrentMonthID == 5 || CurrentMonthID == 6)
                        {
                            strQuarter = "Q1";
                        }
                        else if (CurrentMonthID == 7 || CurrentMonthID == 8 || CurrentMonthID == 9)
                        {
                            strQuarter = "Q2";
                        }
                        else if (CurrentMonthID == 10 || CurrentMonthID == 11 || CurrentMonthID == 12)
                        {
                            strQuarter = "Q3";
                        }
                        else if (CurrentMonthID == 1 || CurrentMonthID == 2 || CurrentMonthID == 3)
                        {
                            strQuarter = "Q4";
                        }

                        if (CurrentMonthID < 4)
                        {
                            string strPreviousYearID = (Convert.ToString(CurrentYearID - 1)).Substring(2, 2);
                            strCurrentYearID = strCurrentYearID.Replace("0", "");
                            strQuarterYear = strPreviousYearID + strCurrentYearID + strQuarter;
                        }
                        else
                        {
                            string strNextYearID = (Convert.ToString(CurrentYearID + 1)).Substring(2, 2);
                            strNextYearID = strNextYearID.Replace("0", "");
                            strQuarterYear = strCurrentYearID + strNextYearID + strQuarter;
                        }

                        objUI.Quarter = strQuarterYear;
                        objUI.Production_Month = Convert.ToInt32(ProductionMonth);
                        objUI.Production_Month_Year = strProductionMonthYear;
                        objUI.FromDate = Convert.ToDateTime(objUtility.ConvertDateTime(gr.Cells[6].Text));
                        objUI.ToDate = Convert.ToDateTime(objUtility.ConvertDateTime(gr.Cells[7].Text));
                        //string strProductionMonthYear = strMonth + "-" + strCurrentYearID;
                       // objUI.Production_Month_Year = strProductionMonthYear;
                    }

                    if (flag == 1)
                    {
                        objCont.SaveProduction(objUI);
                        rcount++;
                    }
                    else
                    {

                        string strQuery = "Insert into ProductionTemp ([Material],[Serial no#],[Plnt],[SLoc],[Description of technical object],[Production_Month],[Production_Month_Year],[IsApproved],MonthID,YearID,[Quarter],IsModelEx,FromDate,ToDate) ";
                        strQuery += "Values ('" + ((TextBox)gr.FindControl("txtMaterial")).Text + "','" + ((TextBox)gr.FindControl("txtSerialNo")).Text + "','" + ((TextBox)gr.FindControl("txtPlnt")).Text + "','" + ((TextBox)gr.FindControl("txtSloc")).Text + "','" + ((TextBox)gr.FindControl("txtDescription")).Text + "','" + ProductionMonth + "','" + strProductionMonthYear + "','0','"+ CurrentMonthID +"','"+ CurrentYearID +"','"+ strQuarterYear +"','"+ modelex +"','" + Convert.ToDateTime(objUtility.ConvertDateTime(gr.Cells[6].Text)) + "','" + Convert.ToDateTime(objUtility.ConvertDateTime(gr.Cells[7].Text)) + "')";
                        objQueryController.ExecuteQuery(strQuery);
                    }

                }
                catch
                {

                    string strQuery = "Insert into ProductionTemp ([Material],[Serial no#],[Plnt],[SLoc],[Description of technical object],[Production_Month],[Production_Month_Year],[IsApproved],MonthID,YearID,[Quarter],IsModelEx,FromDate,ToDate) ";
                    strQuery += "Values ('" + ((TextBox)gr.FindControl("txtMaterial")).Text + "','" + ((TextBox)gr.FindControl("txtSerialNo")).Text + "','" + ((TextBox)gr.FindControl("txtPlnt")).Text + "','" + ((TextBox)gr.FindControl("txtSloc")).Text + "','" + ((TextBox)gr.FindControl("txtDescription")).Text + "','" + ProductionMonth + "','" + strProductionMonthYear + "','0','" + CurrentMonthID + "','" + CurrentYearID + "','" + strQuarterYear + "','" + modelex + "','" + Convert.ToDateTime(objUtility.ConvertDateTime(gr.Cells[6].Text)) + "','" + Convert.ToDateTime(objUtility.ConvertDateTime(gr.Cells[7].Text)) + "')";
                    objQueryController.ExecuteQuery(strQuery);
                }
                string strDeleteQuery = "Delete from ProductionTemp where ID=" + Convert.ToInt16(str);
                objQueryController.ExecuteQuery(strDeleteQuery);

                string strGridQuery = "Select * from Productiontemp";
                DataTable dt = new DataTable();
                dt = objQueryController.ExecuteQuery(strGridQuery);

                grdProdException.DataSource = dt;
                grdProdException.DataBind();
            }
        }
    }
Exemplo n.º 4
0
    public string SaveProduction(DataTable dt)
    {
        string lblMessage = "";
        ProductionController objCont = new ProductionController();

        DataTable dtView = new DataTable();
        string strViewQuery = "Select distinct * from vwMastersCode";
        dtView = objQueryController.ExecuteQuery(strViewQuery);

                string sConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings["connectionString"].ToString();

                int rcount = 0;
                foreach (DataRow dr in dt.Rows)
                {
                    ProductionUI objUI = new ProductionUI();
                    string strCause = "model";
                    int modelex = 1;
                    int ProductionID = Convert.ToInt32(dr["ID"].ToString());

                    try
                    {
                        int flag = 0;

                        string strMaterial = Convert.ToString(dr["Material"]);
                        string strModelQuery = "Select * from ModelMapping where Material='" + strMaterial + "'";
                        DataTable dtModel = objQueryController.ExecuteQuery(strModelQuery);
                        if (dtModel != null)
                        {
                            if (dtModel.Rows.Count > 0)
                            {
                                foreach (DataRow drModel in dtModel.Rows)
                                {
                                    objUI.ModelMappingID = Convert.ToInt32(drModel["ID"].ToString());
                                    strCause = strCause.Replace("model", "");
                                    modelex = 0;
                                    flag++;
                                }
                            }
                        }
                        string strS = Convert.ToString(dr["S"]);
                        if (strS == "")
                        {
                            objUI.S = Convert.ToInt16(null);
                        }
                        else
                        {
                            objUI.S = Convert.ToInt16(dr["S"]);
                        }

                        objUI.Material = Convert.ToString(dr["Material"]);

                        objUI.SerialNo = Convert.ToString(dr["Serial no#"]);
                        objUI.Plnt = Convert.ToString(dr["Plnt"]);

                        string strSLoc = Convert.ToString(dr["SLoc"]);
                        if (strSLoc == "")
                        {
                            objUI.SLoc = Convert.ToString(null);
                        }
                        else
                        {
                            objUI.SLoc = Convert.ToString(dr["SLoc"]);
                        }
                        objUI.Description = Convert.ToString(dr["Description of technical object"]);
                        objUI.Production_Month = Convert.ToInt16(dr["Production_Month"]);
                        objUI.Production_Month_Year = Convert.ToString(dr["Production_Month_Year"]);
                        objUI.FromDate = Convert.ToDateTime(dr["FromDate"]);
                        objUI.ToDate = Convert.ToDateTime(dr["ToDate"]);
                        objUI.MonthID = Convert.ToInt16(dr["MonthID"]);
                        objUI.YearID = Convert.ToInt16(dr["YearID"]);
                        objUI.Quarter = Convert.ToString(dr["Quarter"]);

                        if (flag == 1)
                        {
                            objCont.SaveProduction(objUI);
                            rcount++;

                        }
                        else
                        {

                            string strQuery = "Insert into ProductionTemp ([S],[Material],[Serial no#],[Plnt],[SLoc],[Description of technical object],[Production_Month],[Model_Code],[Production_Month_Year],[IsApproved],MonthID,YearID,[Quarter],IsModelEx,FromDate,ToDate) ";
                            strQuery += "Values ('" + dr["S"].ToString() + "','" + dr["Material"].ToString() + "','" + dr["Serial no."].ToString() + "','" + dr["Plnt"].ToString() + "','" + dr["SLoc"].ToString() + "','" + dr["Description of technical object"].ToString() + "','" + dr["Production_Month"].ToString() + "','" + dr["Model_Code"].ToString() + "','" + dr["Production_Month_Year"].ToString() + "',0,'" + dr["MonthID"].ToString() + "','" + dr["YearID"].ToString() + "','" + dr["Quarter"].ToString() + "','" + modelex + "','" + dr["FromDate"].ToString() + "','" + dr["ToDate"].ToString() + "')";
                            objQueryController.ExecuteQuery(strQuery);
                        }
                        lblMessage = "File Production saved successfully;No of Rows Affected:" + rcount;
                    }
                    catch
                    {
                        string strQuery = "Insert into ProductionTemp ([S],[Material],[Serial no#],[Plnt],[SLoc],[Description of technical object],[Production_Month],[Model_Code],[Production_Month_Year],[IsApproved],MonthID,YearID,[Quarter],IsModelEx,FromDate,ToDate) ";
                        strQuery += "Values ('" + dr["S"].ToString() + "','" + dr["Material"].ToString() + "','" + dr["Serial no."].ToString() + "','" + dr["Plnt"].ToString() + "','" + dr["SLoc"].ToString() + "','" + dr["Description of technical object"].ToString() + "','" + dr["Production_Month"].ToString() + "','" + dr["Model_Code"].ToString() + "','" + dr["Production_Month_Year"].ToString() + "',0,'" + dr["MonthID"].ToString() + "','" + dr["YearID"].ToString() + "','" + dr["Quarter"].ToString() + "','" + modelex + "','" + dr["FromDate"].ToString() + "','" + dr["ToDate"].ToString() + "')";
                        objQueryController.ExecuteQuery(strQuery);
                    }
                    string strDeleteQuery = "Delete from ProductionTemp where [ID]=" + ProductionID;
                    objQueryController.ExecuteQuery(strDeleteQuery);

                }

        return lblMessage;
    }
Exemplo n.º 5
0
    public void SaveProduction(DataTable dt)
    {
        ProductionController objCont = new ProductionController();

        DataTable dtView = new DataTable();
        string strViewQuery = "Select distinct * from vwMastersCode";
        dtView = objQuerycontroller.ExecuteQuery(strViewQuery);

        DataTable dtModel = new DataTable();
        string strModelQuery = "select * from Model";
        dtModel = objQuerycontroller.ExecuteQuery(strModelQuery);

                int rcount = 0;
                foreach (DataRow dr in dt.Rows)
                {
                    ProductionUI objUI = new ProductionUI();
                    string strCause = "model";
                    int modelex = 1;

                    try
                    {
                        int flag = 0;
                        for (int i = 0; i < dtView.Rows.Count; i++)
                        {
                            if ("model" == dtView.Rows[i]["tablename"].ToString() && dr["Model_Code"].ToString() == dtView.Rows[i]["code"].ToString())
                            {
                                DataView dv = new DataView(dtModel);
                                dv.RowFilter = "Code ='" + dr["Model_Code"].ToString() + "'";
                                DataTable dtModelCode = dv.ToTable();
                                objUI.Model_Code = Convert.ToString(dtModelCode.Rows[0]["Model_Code"]);
                                strCause = strCause.Replace("model", "");
                                modelex = 0;
                                flag++;
                            }
                        }
                        string strS = Convert.ToString(dr["S"]);
                        if (strS == "")
                        {
                            objUI.S = Convert.ToInt16(null);
                        }
                        else
                        {
                            objUI.S = Convert.ToInt16(dr["S"]);
                        }

                        objUI.Material = Convert.ToString(dr["Material"]);
                        objUI.SerialNo = Convert.ToString(dr["Serial no#"]);
                        objUI.Plnt = Convert.ToString(dr["Plnt"]);

                        string strSLoc = Convert.ToString(dr["SLoc"]);
                        if (strSLoc == "")
                        {
                            objUI.SLoc = Convert.ToString(null);
                        }
                        else
                        {
                            objUI.SLoc = Convert.ToString(dr["SLoc"]);
                        }
                        objUI.Description = Convert.ToString(dr["Description of technical object"]);
                        objUI.Production_Month = Convert.ToInt16(dr["Production_Month"]);
                        objUI.Production_Month_Year = Convert.ToString(dr["Production_Month_Year"]);
                        //objUI.FromDate = CalProdfromDate.SelectedDate;
                        //objUI.ToDate = CalProdtoDate.SelectedDate;
                        objUI.FromDate = Convert.ToDateTime(dr["FromDate"]);
                        objUI.ToDate = Convert.ToDateTime(dr["ToDate"]);
                        objUI.MonthID = Convert.ToInt16(dr["MonthID"]);
                        objUI.YearID = Convert.ToInt16(dr["YearID"]);
                        objUI.Quarter = Convert.ToString(dr["Quarter"]);

                        if (flag == 1)
                        {
                            objCont.SaveProduction(objUI);
                            rcount++;
                        }
                        else
                        {

                            string strQuery = "Insert into ProductionTemp ([S],[Material],[Serial no#],[Plnt],[SLoc],[Description of technical object],[Production_Month],[Model_Code],[Production_Month_Year],[IsApproved],MonthID,YearID,[Quarter],IsModelEx,FromDate,ToDate) ";
                            strQuery += "Values ('" + dr["S"].ToString() + "','" + dr["Material"].ToString() + "','" + dr["Serial no."].ToString() + "','" + dr["Plnt"].ToString() + "','" + dr["SLoc"].ToString() + "','" + dr["Description of technical object"].ToString() + "','" + dr["Production_Month"].ToString() + "','" + dr["Model_Code"].ToString() + "','" + dr["Production_Month_Year"].ToString() + "',0,'" + dr["MonthID"].ToString() + "','" + dr["YearID"].ToString() + "','" + dr["Quarter"].ToString() + "','" + modelex + "','" + dr["FromDate"].ToString() + "','" + dr["ToDate"].ToString() + "')";
                            objQuerycontroller.ExecuteQuery(strQuery);
                        }

                    }
                    catch
                    {

                        string strQuery = "Insert into ProductionTemp ([S],[Material],[Serial no#],[Plnt],[SLoc],[Description of technical object],[Production_Month],[Model_Code],[Production_Month_Year],[IsApproved],MonthID,YearID,[Quarter],IsModelEx,FromDate,ToDate) ";
                        strQuery += "Values ('" + dr["S"].ToString() + "','" + dr["Material"].ToString() + "','" + dr["Serial no#"].ToString() + "','" + dr["Plnt"].ToString() + "','" + dr["SLoc"].ToString() + "','" + dr["Description of technical object"].ToString() + "','" + dr["Production_Month"].ToString() + "','" + dr["Model_Code"].ToString() + "','" + dr["Production_Month_Year"].ToString() + "',0,'" + dr["MonthID"].ToString() + "','" + dr["YearID"].ToString() + "','" + dr["Quarter"].ToString() + "','" + modelex + "','" + dr["FromDate"].ToString() + "','" + dr["ToDate"].ToString() + "')";
                        objQuerycontroller.ExecuteQuery(strQuery);
                    }

        }
    }