コード例 #1
0
    public static TRetunrLoadData ConfirmData(List <TDataDupicate> lstData, List <TDataFacAndIndicator> lstData_Save)
    {
        PTTGC_EPIEntities db         = new PTTGC_EPIEntities();
        TRetunrLoadData   result     = new TRetunrLoadData();
        string            Del_SQL    = "";
        string            Insert_SQL = "";
        DateTime          now        = DateTime.Now;
        int nUserID = UserAcc.GetObjUser().nUserID;

        if (UserAcc.UserExpired())
        {
            result.Status = SystemFunction.process_SessionExpired;
        }
        else
        {
            if (lstData.Count > 0)
            {
                foreach (var item in lstData)
                {
                    Del_SQL    += @" DELETE FROM mTWorkFlow WHERE IDFac = " + item.nFacID + @" AND IDIndicator = " + item.nIndicatorID + @" ";
                    Insert_SQL += @" INSERT INTO mTWorkFlow (IDFac,IDIndicator,L1,L2,nUpdateID,dUpdate,cDel) VALUES ('" + item.nFacID + @"','" + item.nIndicatorID + @"','" + item.sManagerID + @"','" + item.sEnvironID + @"','" + nUserID + @"','" + now + @"','N') ";
                }
                SystemFunction.ExecuteSQL(SystemFunction.strConnect, Del_SQL);
                SystemFunction.ExecuteSQL(SystemFunction.strConnect, Insert_SQL);
                result.Status = SystemFunction.process_Success;
            }
            else
            {
                result.Status = SystemFunction.process_Failed;
                result.Msg    = "Data not found";
            }

            if (lstData_Save.Count > 0)
            {
                foreach (var item in lstData_Save)
                {
                    Del_SQL    += @" DELETE FROM mTWorkFlow WHERE IDFac = " + item.nFacID + @" AND IDIndicator = " + item.nIndicatorID + @" ";
                    Insert_SQL += @" INSERT INTO mTWorkFlow (IDFac,IDIndicator,L1,L2,nUpdateID,dUpdate,cDel) VALUES ('" + item.nFacID + @"','" + item.nIndicatorID + @"','" + item.sManagerID + @"','" + item.sEnvironID + @"','" + nUserID + @"','" + now + @"','N') ";
                }
                SystemFunction.ExecuteSQL(SystemFunction.strConnect, Del_SQL);
                SystemFunction.ExecuteSQL(SystemFunction.strConnect, Insert_SQL);
                result.Status = SystemFunction.process_Success;
            }
        }


        return(result);
    }
コード例 #2
0
    public static TRetunrLoadData AddOperation(List <string> lst_Operation, List <string> lst_Facility, List <string> lst_GroupIndicator, string sManagerID, string sEnvironID)
    {
        PTTGC_EPIEntities           db               = new PTTGC_EPIEntities();
        TRetunrLoadData             result           = new TRetunrLoadData();
        List <TDataFacAndIndicator> lstData          = new List <TDataFacAndIndicator>();
        List <TDataFacAndIndicator> lstDataToSave    = new List <TDataFacAndIndicator>();
        List <TDataDupicate>        lstDataDuplicate = new List <TDataDupicate>();

        if (!UserAcc.UserExpired())
        {
            Func <int?, int?, bool> CheckDuplicateID = (IDFac, IDIndicator) =>
            {
                bool Isdup = false;
                var  q     = db.mTWorkFlow.Where(w => w.IDFac == IDFac && w.IDIndicator == IDIndicator && w.cDel == "N");
                Isdup = q.Any();
                return(Isdup);
            };

            if (lst_Facility != null)
            {
                int nFacID       = 0;
                int nIndicatorID = 0;
                foreach (var Fac in lst_Facility)
                {
                    nFacID = int.Parse(Fac);
                    var lstFac = db.mTFacility.Where(w => w.ID == nFacID && w.cDel == "N" && w.cActive == "Y").ToList();
                    if (lst_GroupIndicator != null)
                    {
                        foreach (var Indicator in lst_GroupIndicator)
                        {
                            nIndicatorID = int.Parse(Indicator);
                            var lstIndicator = db.mTIndicator.Where(w => w.ID == nIndicatorID).ToList();
                            lstData.Add(new TDataFacAndIndicator
                            {
                                nFacID         = nFacID,
                                sFacName       = lstFac.Any() ? lstFac.First(a => a.ID == nFacID).Name : "",
                                nIndicatorID   = nIndicatorID,
                                sIndicatorName = lstIndicator.Any() ? lstIndicator.First(a => a.ID == nIndicatorID).Indicator : "",
                            });
                        }
                        lstData.Distinct().ToList();
                    }
                }
                string _SQL = "";
                if (lstData.Any())
                {
                    DateTime now     = DateTime.Now;
                    int      nUserID = UserAcc.GetObjUser().nUserID;
                    bool     Ispass  = true;
                    foreach (var item in lstData)
                    {
                        if (!CheckDuplicateID(item.nFacID, item.nIndicatorID))
                        {
                            _SQL += @" INSERT INTO mTWorkFlow (IDFac,IDIndicator,L1,L2,nUpdateID,dUpdate,cDel) VALUES ('" + item.nFacID + @"','" + item.nIndicatorID + @"','" + sManagerID + @"','" + sEnvironID + @"','" + nUserID + @"','" + now + @"','N') ";
                            //result.Status = SystemFunction.process_Success;
                            lstDataToSave.Add(new TDataFacAndIndicator
                            {
                                nFacID         = item.nFacID,
                                nIndicatorID   = item.nIndicatorID,
                                sManagerID     = sManagerID,
                                sEnvironID     = sEnvironID,
                                sFacName       = item.sFacName,
                                sIndicatorName = item.sIndicatorName,
                            });
                        }
                        else
                        {
                            //result.Msg += " (Facility : " + item.sFacName + ") And (Group Indicator : " + item.sIndicatorName + ") ! </br>";
                            result.Status = SystemFunction.process_Failed;
                            Ispass        = false;
                            lstDataDuplicate.Add(new TDataDupicate
                            {
                                nFacID         = item.nFacID,
                                nIndicatorID   = item.nIndicatorID,
                                sManagerID     = sManagerID,
                                sEnvironID     = sEnvironID,
                                sFacName       = item.sFacName,
                                sIndicatorName = item.sIndicatorName,
                            });
                            //return result;
                        }
                    }
                    if (Ispass)
                    {
                        SystemFunction.ExecuteSQL(SystemFunction.strConnect, _SQL);
                        result.Status = SystemFunction.process_Success;
                    }
                }
            }
        }
        else
        {
            result.Status = SystemFunction.process_SessionExpired;
        }
        if (lstDataDuplicate.Any())
        {
            var lstFacility = lstDataDuplicate.Select(s => s.nFacID).Distinct().ToList();
            if (lstFacility.Any())
            {
                result.Msg = " Facilities has been saved. Do you want to save again ?</br></br>";
                foreach (var i in lstFacility)
                {
                    int nFacID = i;
                    var lst    = lstDataDuplicate.Where(w => w.nFacID == nFacID).ToList();
                    if (lst.Any())
                    {
                        result.Msg += " Facility : " + lst.First().sFacName + " </br>";
                        lst.ForEach(f =>
                        {
                            result.Msg += " - Group Indicator : " + f.sIndicatorName + " </br>";
                        });
                        result.Msg += "</br>";
                    }
                }
            }
        }
        result.lstToSave    = lstDataToSave.Distinct().ToList();
        result.lstDuplicate = lstDataDuplicate.Distinct().ToList();
        result.lstMapping   = lstData.Distinct().ToList();
        return(result);
    }