示例#1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="costCenterMaster"></param>
        /// <param name="userInformation"></param>
        /// <returns></returns>
        public bool GetCostCenterMaster(ref CostCenterMaster costCenterMaster)
        {
            try
            {
                string           code;
                DDCOST_CENT_MAST ddCC;
                code = costCenterMaster.CostCentCode;

                /*
                 * costCenterMaster=(from c in DB.DDCOST_CENT_MAST
                 *                  where c.COST_CENT_CODE == code
                 *                  select costCenterMaster
                 *                  {
                 *                      CostCentCode = c.COST_CENT_CODE,
                 *                      CostCentDesc = c.COST_CENT_DESC,
                 *                      CateCode = c.CATE_CODE,
                 *                      LocCode = c.LOC_CODE,
                 *                      Module = c.MODULE,
                 *                      Efficiency = Convert.ToDouble(c.EFFICIENCY),
                 *                      MachineName = c.MACHINE_NAME
                 *                  }).SingleOrDefault<CostCenterMaster>();
                 */
                ddCC = (from c in DB.DDCOST_CENT_MAST
                        where c.COST_CENT_CODE == code
                        select c).SingleOrDefault();


                if (costCenterMaster.IsNotNullOrEmpty() == false)
                {
                    costCenterMaster = new CostCenterMaster();
                }

                if (ddCC.IsNotNullOrEmpty())
                {
                    costCenterMaster.CostCentCode = ddCC.COST_CENT_CODE;
                    costCenterMaster.CostCentDesc = ddCC.COST_CENT_DESC;
                    costCenterMaster.CateCode     = ddCC.CATE_CODE;
                    costCenterMaster.LocCode      = ddCC.LOC_CODE;
                    costCenterMaster.Module       = ddCC.MODULE;

                    if (ddCC.EFFICIENCY == null)
                    {
                        costCenterMaster.Efficiency = 0;
                    }
                    else
                    {
                        costCenterMaster.Efficiency = Convert.ToDouble(ddCC.EFFICIENCY >= 100 ? 0 : ddCC.EFFICIENCY);
                    }
                    costCenterMaster.MachineName = ddCC.MACHINE_NAME;
                    costCenterMaster.FilePath    = "";
                }
                return(true);
            }
            catch (Exception ex)
            {
                throw ex.LogException();
            }
        }
示例#2
0
        private bool SaveOperations(CostCenterMaster costcentermaster)
        {
            EnumerableRowCollection <DDCC_OPER> ddoperations = null;
            bool submit = false;

            try
            {
                ddoperations = from row in costcentermaster.Operation.AsEnumerable()
                               select new DDCC_OPER
                {
                    COST_CENT_CODE = costcentermaster.CostCentCode,
                    OPN_CODE       = row["opn_code"].ToString().ToDecimalValue(),
                    UNIT_CODE      = row["unit_code"].ToString(),
                    FIX_COST       = row["fix_cost"].ToString().ToDecimalValue(),
                    VAR_COST       = row["var_cost"].ToString().ToDecimalValue(),
                };
                foreach (DDCC_OPER ddoper in ddoperations)
                {
                    if (ddoper.OPN_CODE.ToValueAsString() != "" && ddoper.UNIT_CODE.ToValueAsString() != "")
                    {
                        ddoper.ROWID = Guid.NewGuid();
                        DB.DDCC_OPER.InsertOnSubmit(ddoper);
                    }
                }
                submit = true;
                DB.SubmitChanges();
                return(true);
            }
            catch (System.Data.Linq.ChangeConflictException ex)
            {
                DB.ChangeConflicts.ResolveAll(System.Data.Linq.RefreshMode.KeepChanges);
                ex.LogException();
                return(false);
            }
            catch (Exception ex)
            {
                if (submit == true)
                {
                    DB.DDCC_OPER.DeleteAllOnSubmit(ddoperations);
                }
                throw ex.LogException();
            }
        }
示例#3
0
 private bool SaveCostDetails(CostCenterMaster costcentermaster)
 {
     try
     {
         DeleteOutPut(costcentermaster.CostCentCode);
         DeleteOperations(costcentermaster.CostCentCode);
         //SaveOutput(costcentermaster);
         SaveOperations(costcentermaster);
         SaveOutPut(costcentermaster);
         if (costcentermaster.PhotoChanged == true)
         {
             SaveDrawing(costcentermaster);
         }
         return(true);
     }
     catch (Exception ex)
     {
         throw ex.LogException();
     }
 }
示例#4
0
        private bool SaveOutPut(CostCenterMaster costcentermaster)
        {
            EnumerableRowCollection <DDCC_OUTPUT> ddoutputs = null;
            bool submit = false;

            try
            {
                ddoutputs = from row in costcentermaster.Output.AsEnumerable()
                            select new DDCC_OUTPUT
                {
                    COST_CENT_CODE = costcentermaster.CostCentCode,
                    OUTPUT         = row["output"].ToString().ToDecimalValue()
                };
                foreach (DDCC_OUTPUT ddout in ddoutputs)
                {
                    if (ddout.OUTPUT.ToValueAsString() != "")
                    {
                        ddout.ROWID = Guid.NewGuid();
                        DB.DDCC_OUTPUT.InsertOnSubmit(ddout);
                    }
                }
                submit = true;
                DB.SubmitChanges();
                return(true);
            }
            catch (System.Data.Linq.ChangeConflictException ex)
            {
                DB.ChangeConflicts.ResolveAll(System.Data.Linq.RefreshMode.KeepChanges);
                ex.LogException();
                return(false);
            }
            catch (Exception ex)
            {
                if (submit == true)
                {
                    DB.DDCC_OUTPUT.DeleteAllOnSubmit(ddoutputs);
                }
                throw ex.LogException();
            }
        }
示例#5
0
        ////[DllImport(@"urlmon.dll", CharSet = CharSet.Auto)]
        ////private extern static System.UInt32 FindMimeFromData(
        ////    System.UInt32 pBC,
        ////    [MarshalAs(UnmanagedType.LPStr)] System.String pwzUrl,
        ////    [MarshalAs(UnmanagedType.LPArray)] byte[] pBuffer,
        ////    System.UInt32 cbSize,
        ////    [MarshalAs(UnmanagedType.LPStr)] System.String pwzMimeProposed,
        ////    System.UInt32 dwMimeFlags,
        ////    out System.UInt32 ppwzMimeOut,
        ////    System.UInt32 dwReserverd
        ////);


        ////public string getMimeFromFile(byte[] byteArray)
        ////{

        ////    byte[] buffer = new byte[256];
        ////    using (System.IO.MemoryStream fs = new System.IO.MemoryStream(byteArray))
        ////    {
        ////        if (fs.Length >= 256)
        ////            fs.Read(buffer, 0, 256);
        ////        else
        ////            fs.Read(buffer, 0, (int)fs.Length);
        ////    }
        ////    try
        ////    {
        ////        System.UInt32 mimetype;
        ////        FindMimeFromData(0, null, buffer, 256, null, 0, out mimetype, 0);
        ////        System.IntPtr mimeTypePtr = new IntPtr(mimetype);
        ////        string mime = Marshal.PtrToStringUni(mimeTypePtr);
        ////        Marshal.FreeCoTaskMem(mimeTypePtr);
        ////        return mime;
        ////    }
        ////    catch (Exception e)
        ////    {
        ////        return e.Message;
        ////    }
        ////}


        private bool SaveDrawing(CostCenterMaster costcentermaster)
        {
            ///SaveDrawingSQL(costcentermaster);
            //return true;
            DDCOST_CENT_DWG ddDrawing = null;
            bool            submit    = false;
            bool            insert    = false;
            bool            update    = false;

            try
            {
                ddDrawing = (from c in DB.DDCOST_CENT_DWG
                             where c.COST_CENT_CODE == costcentermaster.CostCentCode
                             select c).SingleOrDefault <DDCOST_CENT_DWG>();
                if (ddDrawing.IsNotNullOrEmpty())
                {
                    ddDrawing.UPDATED_BY   = userInformation.UserName;
                    ddDrawing.UPDATED_DATE = serverDateTime;
                    ddDrawing.DELETE_FLAG  = false;
                    if (costcentermaster.Photo != null)
                    {
                        //ddDrawing.PHOTO = System.IO.File.ReadAllBytes(costcentermaster.ImageByte);
                        ddDrawing.PHOTO     = costcentermaster.ImageByte;
                        ddDrawing.FILE_PATH = costcentermaster.FilePath;
                    }
                    update = true;
                }
                else
                {
                    ddDrawing                = new DDCOST_CENT_DWG();
                    ddDrawing.ENTERED_BY     = userInformation.UserName;
                    ddDrawing.ENTERED_DATE   = serverDate;
                    ddDrawing.DELETE_FLAG    = false;
                    ddDrawing.COST_CENT_CODE = costcentermaster.CostCentCode;
                    ddDrawing.PHOTO          = costcentermaster.ImageByte;
                    ddDrawing.FILE_PATH      = costcentermaster.FilePath;
                    insert = true;
                    DB.DDCOST_CENT_DWG.InsertOnSubmit(ddDrawing);
                }
                submit = true;
                DB.SubmitChanges();
                return(true);
            }
            catch (System.Data.Linq.ChangeConflictException ex)
            {
                DB.ChangeConflicts.ResolveAll(System.Data.Linq.RefreshMode.KeepChanges);
                ex.LogException();
                return(false);
            }
            catch (Exception ex)
            {
                if (submit == true)
                {
                    if (insert == true)
                    {
                        DB.DDCOST_CENT_DWG.DeleteOnSubmit(ddDrawing);
                    }
                    if (update == true)
                    {
                        DB.DDCOST_CENT_DWG.Context.Refresh(System.Data.Linq.RefreshMode.OverwriteCurrentValues, ddDrawing);
                    }
                }
                throw ex.LogException();
            }
        }
示例#6
0
        /// <summary>
        ///
        ///
        /// </summary>
        /// <param name="costCenterMaster"></param>
        /// <param name="mode"></param>
        /// <returns></returns>
        public bool SaveCostCenterMaster(CostCenterMaster costCenterMaster, OperationMode opermode)
        {
            DDCOST_CENT_MAST ddCC   = null;
            bool             insert = false;
            bool             update = false;
            bool             submit = false;

            try
            {
                ddCC = new DDCOST_CENT_MAST();

                if (opermode == OperationMode.AddNew)
                {
                    ddCC = new DDCOST_CENT_MAST();
                }
                else
                {
                    ddCC = (from c in DB.DDCOST_CENT_MAST
                            where c.COST_CENT_CODE == costCenterMaster.CostCentCode
                            select c).Single <DDCOST_CENT_MAST>();
                }
                ddCC.COST_CENT_CODE = costCenterMaster.CostCentCode;
                ddCC.COST_CENT_DESC = costCenterMaster.CostCentDesc;
                ddCC.CATE_CODE      = costCenterMaster.CateCode;
                ddCC.LOC_CODE       = costCenterMaster.LocCode;
                ddCC.MODULE         = costCenterMaster.Module;
                ddCC.EFFICIENCY     = Convert.ToDecimal(costCenterMaster.Efficiency);
                ddCC.MACHINE_NAME   = costCenterMaster.MachineName;
                ddCC.DELETE_FLAG    = false;

                if (opermode == OperationMode.AddNew)
                {
                    ddCC.ENTERED_BY   = userInformation.UserName;
                    ddCC.ENTERED_DATE = serverDateTime;
                    insert            = true;
                    DB.DDCOST_CENT_MAST.InsertOnSubmit(ddCC);
                }
                else
                {
                    ddCC.UPDATED_BY   = userInformation.UserName;
                    ddCC.UPDATED_DATE = serverDateTime;
                    update            = true;
                }
                submit = true;
                DB.SubmitChanges();
                SaveCostDetails(costCenterMaster);
                return(true);
            }
            catch (Exception ex)
            {
                if (submit == true)
                {
                    if (update == true)
                    {
                        DB.DDCOST_CENT_MAST.Context.Refresh(System.Data.Linq.RefreshMode.OverwriteCurrentValues, ddCC);
                    }
                    if (insert == true)
                    {
                        DB.DDCOST_CENT_MAST.DeleteOnSubmit(ddCC);
                    }
                }
                throw ex.LogException();
            }
        }