コード例 #1
0
        public string DelUpdateSizingChemicalMasterDetail(vmCmnParameters objcmnParam)
        {
            string result = "";

            using (var transaction = new TransactionScope())
            {
                GFactory_EF_PrdSizingChemicalConsumption       = new PrdSizingChemicalConsumption_EF();
                GFactory_EF_PrdSizingChemicalconsumptionDetail = new PrdSizingChemicalconsumptionDetail_EF();

                var MasterItem = new PrdSizingChemicalConsumption();
                var DetailItem = new List <PrdSizingChemicalconsumptionDetail>();

                //For Update Master Detail
                var MasterAll = GFactory_EF_PrdSizingChemicalConsumption.GetAll().Where(x => x.ChemicalConsumptionID == objcmnParam.id && x.CompanyID == objcmnParam.loggedCompany);
                var DetailAll = GFactory_EF_PrdSizingChemicalconsumptionDetail.GetAll().Where(x => x.ChemicalConsumptionID == objcmnParam.id && x.CompanyID == objcmnParam.loggedCompany);
                //-------------------END----------------------

                try
                {
                    MasterItem           = MasterAll.First(x => x.ChemicalConsumptionID == objcmnParam.id);
                    MasterItem.CompanyID = objcmnParam.loggedCompany;
                    MasterItem.DeleteBy  = objcmnParam.loggeduser;
                    MasterItem.DeleteOn  = DateTime.Now;
                    MasterItem.DeletePc  = HostService.GetIP();
                    MasterItem.IsDeleted = true;

                    foreach (PrdSizingChemicalconsumptionDetail d in DetailAll.Where(d => d.ChemicalConsumptionID == objcmnParam.id))
                    {
                        d.CompanyID = objcmnParam.loggedCompany;
                        d.DeleteBy  = objcmnParam.loggeduser;
                        d.DeleteOn  = DateTime.Now;
                        d.DeletePc  = HostService.GetIP();
                        d.IsDeleted = true;

                        DetailItem.Add(d);
                    }

                    if (MasterItem != null)
                    {
                        GFactory_EF_PrdSizingChemicalConsumption.Update(MasterItem);
                        GFactory_EF_PrdSizingChemicalConsumption.Save();
                    }
                    if (DetailItem != null)
                    {
                        GFactory_EF_PrdSizingChemicalconsumptionDetail.UpdateList(DetailItem.ToList());
                        GFactory_EF_PrdSizingChemicalconsumptionDetail.Save();
                    }

                    transaction.Complete();
                    result = "1";
                }
                catch (Exception e)
                {
                    result = "";
                    e.ToString();
                }
            }
            return(result);
        }
コード例 #2
0
        public string SaveUpdateSizingChemicalMasterDetail(vmChemicalSetupMasterDetail Master, List <vmChemicalSetupMasterDetail> Detail, vmCmnParameters objcmnParam)
        {
            string result = string.Empty;

            using (var transaction = new TransactionScope())
            {
                //*********************************************Start Initialize Variable*****************************************
                long MasterId = 0, DetailId = 0, FirstDigit = 0, OtherDigits = 0;
                //***************************************End Initialize Variable*************************************************

                //**************************Start Initialize Generic Repository Based on table***********************************
                GFactory_EF_PrdSizingChemicalConsumption       = new PrdSizingChemicalConsumption_EF();
                GFactory_EF_PrdSizingChemicalconsumptionDetail = new PrdSizingChemicalconsumptionDetail_EF();
                //****************************End Initialize Generic Repository Based on table***********************************

                //**********************************Start Create Related Table Instance to Save**********************************
                var MasterItem = new PrdSizingChemicalConsumption();
                var DetailItem = new List <PrdSizingChemicalconsumptionDetail>();
                //************************************End Create Related Table Instance to Save**********************************

                //*************************************Start Create Model Instance to get Data***********************************
                vmChemicalSetupMasterDetail item = new vmChemicalSetupMasterDetail();
                //***************************************End Create Model Instance to get Data***********************************
                //**************************************************Start Main Operation************************************************
                if (Detail.Count > 0)
                {
                    try
                    {
                        if (Master.ChemicalConsumptionID == 0)
                        {
                            //***************************************************Start Save Operation************************************************
                            //**********************************************Start Generate Master & Detail ID****************************************
                            MasterId    = Convert.ToInt16(GFactory_EF_PrdSizingChemicalConsumption.getMaxID("PrdSizingChemicalConsumption"));
                            DetailId    = Convert.ToInt64(GFactory_EF_PrdSizingChemicalconsumptionDetail.getMaxID("PrdSizingChemicalconsumptionDetail"));
                            FirstDigit  = Convert.ToInt64(DetailId.ToString().Substring(0, 1));
                            OtherDigits = Convert.ToInt64(DetailId.ToString().Substring(1, DetailId.ToString().Length - 1));
                            //***********************************************End Generate Master & Detail ID*****************************************

                            MasterItem = new PrdSizingChemicalConsumption
                            {
                                ChemicalConsumptionID = MasterId,
                                DepartmentID          = (int)objcmnParam.DepartmentID,
                                ItemID          = (long)Master.ItemID,
                                SetID           = Master.SetID,
                                UserID          = objcmnParam.loggeduser,
                                ConsumptionDate = Master.ConsumptionDate,
                                Remarks         = Master.Remarks,

                                CompanyID = objcmnParam.loggedCompany,
                                CreateBy  = objcmnParam.loggeduser,
                                CreateOn  = DateTime.Now,
                                CreatePc  = HostService.GetIP(),
                                IsDeleted = false
                            };

                            for (int i = 0; i < Detail.Count; i++)
                            {
                                item = Detail[i];
                                var Detailitem = new PrdSizingChemicalconsumptionDetail
                                {
                                    ChemicalConsumptionDetailID = Convert.ToInt64(FirstDigit + "" + OtherDigits),
                                    ChemicalConsumptionID       = MasterId,
                                    ChemicalID      = (long)item.ChemicalID,
                                    Qty             = item.Qty,
                                    UnitID          = (int)item.UnitID,
                                    Amount          = item.Amount,
                                    BatchID         = item.BatchID,
                                    SupplierID      = item.SupplierID,
                                    UnitPrice       = item.UnitPrice,
                                    ConsumptionDate = Master.ConsumptionDate,

                                    TransactionTypeID = objcmnParam.tTypeId,
                                    DepartmentID      = objcmnParam.DepartmentID,
                                    CompanyID         = objcmnParam.loggedCompany,
                                    CreateBy          = objcmnParam.loggeduser,
                                    CreateOn          = DateTime.Now,
                                    CreatePc          = HostService.GetIP(),
                                    IsDeleted         = false
                                };
                                DetailItem.Add(Detailitem);
                                OtherDigits++;
                            }
                            //***************************************************End Save Operation************************************************
                        }
                        else
                        {
                            //***********************************Start Get Data From Related Table to Update*********************************
                            var MasterAll = GFactory_EF_PrdSizingChemicalConsumption.GetAll().Where(x => x.ChemicalConsumptionID == Master.ChemicalConsumptionID && x.CompanyID == objcmnParam.loggedCompany);
                            var DetailAll = GFactory_EF_PrdSizingChemicalconsumptionDetail.GetAll().Where(x => x.ChemicalConsumptionID == Master.ChemicalConsumptionID && x.CompanyID == objcmnParam.loggedCompany).ToList();
                            //*************************************End Get Data From Related Table to Update*********************************

                            //***************************************************Start Update Operation********************************************
                            MasterItem = MasterAll.First(x => x.ChemicalConsumptionID == Master.ChemicalConsumptionID);
                            MasterItem.DepartmentID    = (int)objcmnParam.DepartmentID;
                            MasterItem.ItemID          = (long)Master.ItemID;
                            MasterItem.SetID           = Master.SetID;
                            MasterItem.UserID          = objcmnParam.loggeduser;
                            MasterItem.ConsumptionDate = Master.ConsumptionDate;
                            MasterItem.Remarks         = Master.Remarks;

                            MasterItem.CompanyID = objcmnParam.loggedCompany;
                            MasterItem.UpdateBy  = objcmnParam.loggeduser;
                            MasterItem.UpdateOn  = DateTime.Now;
                            MasterItem.UpdatePc  = HostService.GetIP();
                            MasterItem.IsDeleted = false;

                            for (int i = 0; i < Detail.Count; i++)
                            {
                                item = Detail[i];
                                foreach (PrdSizingChemicalconsumptionDetail d in DetailAll.Where(d => d.ChemicalConsumptionID == Master.ChemicalConsumptionID && d.ChemicalConsumptionDetailID == item.ChemicalConsumptionDetailID))
                                {
                                    d.ChemicalID      = (long)item.ChemicalID;
                                    d.Qty             = item.Qty;
                                    d.UnitID          = (int)item.UnitID;
                                    d.Amount          = item.Amount;
                                    d.BatchID         = item.BatchID;
                                    d.SupplierID      = item.SupplierID;
                                    d.UnitPrice       = item.UnitPrice;
                                    d.ConsumptionDate = Master.ConsumptionDate;

                                    d.CompanyID = objcmnParam.loggedCompany;
                                    d.UpdateBy  = objcmnParam.loggeduser;
                                    d.UpdateOn  = DateTime.Now;
                                    d.UpdatePc  = HostService.GetIP();
                                    d.IsDeleted = false;

                                    DetailItem.Add(d);
                                    break;
                                }
                            }
                            //***************************************************End Update Operation********************************************
                        }

                        if (Master.ChemicalConsumptionID > 0)
                        {
                            //***************************************************Start Update************************************************
                            if (MasterItem != null)
                            {
                                GFactory_EF_PrdSizingChemicalConsumption.Update(MasterItem);
                                GFactory_EF_PrdSizingChemicalConsumption.Save();
                            }
                            if (DetailItem != null && DetailItem.Count != 0)
                            {
                                GFactory_EF_PrdSizingChemicalconsumptionDetail.UpdateList(DetailItem.ToList());
                                GFactory_EF_PrdSizingChemicalconsumptionDetail.Save();
                            }
                            //***************************************************End Update************************************************
                        }
                        else
                        {
                            //***************************************************Start Save************************************************
                            if (MasterItem != null)
                            {
                                GFactory_EF_PrdSizingChemicalConsumption.Insert(MasterItem);
                                GFactory_EF_PrdSizingChemicalConsumption.Save();
                                GFactory_EF_PrdSizingChemicalConsumption.updateMaxID("PrdSizingChemicalConsumption", Convert.ToInt64(MasterId));
                            }
                            if (DetailItem != null && DetailItem.Count != 0)
                            {
                                GFactory_EF_PrdSizingChemicalconsumptionDetail.InsertList(DetailItem.ToList());
                                GFactory_EF_PrdSizingChemicalconsumptionDetail.Save();
                                GFactory_EF_PrdSizingChemicalconsumptionDetail.updateMaxID("PrdSizingChemicalconsumptionDetail", Convert.ToInt64(FirstDigit + "" + (OtherDigits - 1)));
                            }
                            //******************************************************End Save************************************************
                        }

                        transaction.Complete();
                        result = "1";
                    }
                    catch (Exception e)
                    {
                        result = "";
                        e.ToString();
                    }
                }
                else
                {
                    result = "";
                }
            }
            return(result);
            //**************************************************End Main Operation************************************************
        }