예제 #1
0
        /// <summary>
        /// Update record by using primary key value on the given data variable
        /// </summary>
        /// <param name="database"></param>
        /// <param name="data">Data with primary key value.</param>
        /// <returns></returns>
        public int UpdateWithoutPK(Database database, ItemMachineDTO data)
        {
            Database db = UseDatabase(database);

            StringBuilder sb = new StringBuilder();

            #region SQL Statement
            sb.AppendLine(" UPDATE " + data.TableName);
            sb.AppendLine(" SET ");
            sb.AppendLine("  " + ItemMachineDTO.eColumns.UPD_BY + "=@UPD_BY");
            sb.AppendLine("  ," + ItemMachineDTO.eColumns.UPD_DATE + "=GETDATE()");
            sb.AppendLine("  ," + ItemMachineDTO.eColumns.UPD_MACHINE + "=@UPD_MACHINE");
            sb.AppendLine("  ," + ItemMachineDTO.eColumns.MACHINE_PROCESS + "=@MACHINE_PROCESS");
            sb.AppendLine("  ," + ItemMachineDTO.eColumns.MACHINE_TYPE + "=@MACHINE_TYPE");
            sb.AppendLine("  ," + ItemMachineDTO.eColumns.OLD_DATA + "=@OLD_DATA");
            sb.AppendLine(" WHERE ");
            sb.AppendLine("  " + ItemMachineDTO.eColumns.ITEM_CD + "=@ITEM_CD");
            sb.AppendLine("  AND " + ItemMachineDTO.eColumns.RUN_NO + "=@RUN_NO");
            #endregion

            DataRequest req = new DataRequest(sb.ToString());
            #region Parameters
            req.Parameters.Add("@UPD_BY", DataType.NVarChar, data.UPD_BY.Value);
            req.Parameters.Add("@UPD_MACHINE", DataType.NVarChar, data.UPD_MACHINE.Value);
            req.Parameters.Add("@ITEM_CD", DataType.Default, data.ITEM_CD.Value);
            req.Parameters.Add("@RUN_NO", DataType.Default, data.RUN_NO.Value);
            req.Parameters.Add("@MACHINE_PROCESS", DataType.NVarChar, data.MACHINE_PROCESS.Value);
            req.Parameters.Add("@MACHINE_TYPE", DataType.NVarChar, data.MACHINE_TYPE.Value);
            req.Parameters.Add("@OLD_DATA", DataType.Default, data.OLD_DATA.Value);
            #endregion

            return(db.ExecuteNonQuery(req));
        }
예제 #2
0
        /// <summary>
        /// Check exist before manipulate data. If found record will update data. Otherwise insert new data.
        /// </summary>
        /// <param name="database"></param>
        /// <param name="data"></param>
        /// <returns></returns>
        public int AddNewOrUpdate(Database database, ItemMachineDTO data)
        {
            Database db = UseDatabase(database);

            if (Exist(database, data.ITEM_CD, data.RUN_NO))
            {
                return(UpdateWithoutPK(db, data));
            }

            return(AddNew(db, data));
        }
예제 #3
0
        public ItemUIDM()
        {
            ItemViewProcessDTO dto = new ItemViewProcessDTO();

            dto.CreateDataTableSchema(out m_dtDataView);

            ItemComponentDTO dtoComponent = new ItemComponentDTO();

            dtoComponent.CreateDataTableSchema(out m_dtDataComponentView);

            ItemMachineDTO dtoItemMachine = new ItemMachineDTO();

            dtoItemMachine.CreateDataTableSchema(out m_dtDataItemMachine);
        }
예제 #4
0
        /// <summary>
        /// Insert new record into database.
        /// </summary>
        /// <param name="database"></param>
        /// <param name="data"></param>
        /// <returns></returns>
        public int AddNew(Database database, ItemMachineDTO data)
        {
            Database db = UseDatabase(database);

            StringBuilder sb = new StringBuilder();

            #region SQL Statement
            sb.AppendLine(" INSERT INTO " + data.TableName + "(");
            sb.AppendLine("  " + ItemMachineDTO.eColumns.CRT_BY);
            sb.AppendLine("  ," + ItemMachineDTO.eColumns.CRT_DATE);
            sb.AppendLine("  ," + ItemMachineDTO.eColumns.CRT_MACHINE);
            sb.AppendLine("  ," + ItemMachineDTO.eColumns.UPD_BY);
            sb.AppendLine("  ," + ItemMachineDTO.eColumns.UPD_DATE);
            sb.AppendLine("  ," + ItemMachineDTO.eColumns.UPD_MACHINE);
            sb.AppendLine("  ," + ItemMachineDTO.eColumns.ITEM_CD);
            sb.AppendLine("  ," + ItemMachineDTO.eColumns.RUN_NO);
            sb.AppendLine("  ," + ItemMachineDTO.eColumns.MACHINE_PROCESS);
            sb.AppendLine("  ," + ItemMachineDTO.eColumns.MACHINE_TYPE);
            sb.AppendLine("  ," + ItemMachineDTO.eColumns.OLD_DATA);
            sb.AppendLine(") VALUES(");
            sb.AppendLine("   @CRT_BY");
            sb.AppendLine("   ,GETDATE()");
            sb.AppendLine("   ,@CRT_MACHINE");
            sb.AppendLine("   ,@UPD_BY");
            sb.AppendLine("   ,GETDATE()");
            sb.AppendLine("   ,@UPD_MACHINE");
            sb.AppendLine("   ,@ITEM_CD");
            sb.AppendLine("   ,@RUN_NO");
            sb.AppendLine("   ,@MACHINE_PROCESS");
            sb.AppendLine("   ,@MACHINE_TYPE");
            sb.AppendLine("   ,@OLD_DATA");
            sb.AppendLine(" )");
            #endregion

            DataRequest req = new DataRequest(sb.ToString());
            #region Parameters
            req.Parameters.Add("@CRT_BY", DataType.NVarChar, data.CRT_BY.Value);
            req.Parameters.Add("@CRT_MACHINE", DataType.NVarChar, data.CRT_MACHINE.Value);
            req.Parameters.Add("@UPD_BY", DataType.NVarChar, data.UPD_BY.Value);
            req.Parameters.Add("@UPD_MACHINE", DataType.NVarChar, data.UPD_MACHINE.Value);
            req.Parameters.Add("@ITEM_CD", DataType.Default, data.ITEM_CD.Value);
            req.Parameters.Add("@RUN_NO", DataType.Default, data.RUN_NO.Value);
            req.Parameters.Add("@MACHINE_PROCESS", DataType.NVarChar, data.MACHINE_PROCESS.Value);
            req.Parameters.Add("@MACHINE_TYPE", DataType.NVarChar, data.MACHINE_TYPE.Value);
            req.Parameters.Add("@OLD_DATA", DataType.Default, data.OLD_DATA.Value);
            #endregion

            return(db.ExecuteNonQuery(req));
        }
예제 #5
0
        internal void AddNewItem(ItemUIDM uidmItem)
        {
            ValidateException validationException = new ValidateException();
            ItemValidator     itemValidator       = new ItemValidator();

            itemValidator.CheckItemExist(uidmItem.ITEM_CD);
            //validationException.AddError(businessException.Error);
            //validationException.ThrowIfHasError();

            #region dtoItem

            ItemDTO dtoItem = new ItemDTO();
            dtoItem.CRT_BY         = CommonLib.Common.CurrentUserInfomation.UserCD;
            dtoItem.CRT_DATE.Value = CommonLib.Common.GetDatabaseDateTime();
            dtoItem.CRT_MACHINE    = CommonLib.Common.CurrentUserInfomation.Machine;
            dtoItem.UPD_BY         = CommonLib.Common.CurrentUserInfomation.UserCD;
            dtoItem.UPD_DATE.Value = CommonLib.Common.GetDatabaseDateTime();
            dtoItem.UPD_MACHINE    = CommonLib.Common.CurrentUserInfomation.Machine;

            dtoItem.ITEM_CD      = uidmItem.ITEM_CD;
            dtoItem.SHORT_NAME   = uidmItem.SHORT_NAME;
            dtoItem.ITEM_DESC    = uidmItem.ITEM_DESC;
            dtoItem.ROUTING_TEXT = uidmItem.ROUTING_TEXT;

            #region Product Tab

            dtoItem.KIND_OF_PRODUCT    = uidmItem.KIND_OF_PRODUCT;
            dtoItem.CUSTOMER_CD        = uidmItem.CUSTOMER_CD;
            dtoItem.CUSTOMER_USE_POINT = uidmItem.CUSTOMER_USE_POINT;
            dtoItem.WEIGHT             = uidmItem.WEIGHT;
            dtoItem.BOI             = uidmItem.BOI;
            dtoItem.PRODUCTION_DI   = uidmItem.PRODUCTION_DI;
            dtoItem.ITEM_LEVEL      = uidmItem.ITEM_LEVEL;
            dtoItem.MAT_NAME        = uidmItem.MAT_NAME;
            dtoItem.MAT_SIZE        = uidmItem.MAT_SIZE;
            dtoItem.MAT_SUPPLIER_CD = uidmItem.SUPPLIER_NAME;
            dtoItem.KIND_OF_MAT     = uidmItem.KIND_OF_MAT;
            dtoItem.MAT_DI          = uidmItem.MAT_DI;
            dtoItem.REMARK          = uidmItem.REMARK;

            #endregion

            #region Screw Tab

            dtoItem.SCREW_KIND    = uidmItem.SCREW_KIND;
            dtoItem.SCREW_HEAD    = uidmItem.SCREW_HEAD;
            dtoItem.SCREW_M       = uidmItem.SCREW_M;
            dtoItem.SCREW_L       = uidmItem.SCREW_L;
            dtoItem.SCREW_TYPE    = uidmItem.SCREW_TYPE;
            dtoItem.SCREW_REMARK1 = uidmItem.SCREW_REMARK1;
            dtoItem.SCREW_REMARK2 = uidmItem.SCREW_REMARK2;
            dtoItem.HEXABULAR     = uidmItem.HEXABULAR;

            #endregion

            #region Machine Tab

            dtoItem.PROCESS1      = uidmItem.PROCESS1;
            dtoItem.MACHINE_TYPE1 = uidmItem.MACHINE_TYPE1;
            dtoItem.PROCESS2      = uidmItem.PROCESS2;
            dtoItem.MACHINE_TYPE2 = uidmItem.MACHINE_TYPE2;
            dtoItem.PROCESS3      = uidmItem.PROCESS3;
            dtoItem.MACHINE_TYPE3 = uidmItem.MACHINE_TYPE3;
            dtoItem.PROCESS4      = uidmItem.PROCESS4;
            dtoItem.MACHINE_TYPE4 = uidmItem.MACHINE_TYPE4;
            dtoItem.PROCESS5      = uidmItem.PROCESS5;
            dtoItem.MACHINE_TYPE5 = uidmItem.MACHINE_TYPE5;
            dtoItem.PROCESS6      = uidmItem.PROCESS6;
            dtoItem.MACHINE_TYPE6 = uidmItem.MACHINE_TYPE6;

            #endregion

            #region Heat Treatment Tab

            dtoItem.HEAT_FLAG          = uidmItem.HEAT_FLAG;
            dtoItem.HEAT_TYPE          = uidmItem.HEAT_TYPE;
            dtoItem.HEAT_HARDNESS      = uidmItem.HEAT_HARDNESS;
            dtoItem.HEAT_CORE_HARDNESS = uidmItem.HEAT_CORE_HARDNESS;
            dtoItem.HEAT_CASE_DEPTH    = uidmItem.HEAT_CASE_DEPTH;

            #endregion

            #region Plating Tab

            dtoItem.PLATING_FLAG         = uidmItem.PLATING_FLAG;
            dtoItem.PLATING_KIND         = uidmItem.PLATING_KIND;
            dtoItem.PLATING_SUPPLIER_CD  = uidmItem.PLATING_SUPPLIER_NAME;
            dtoItem.PLATING_THICKNESS1_1 = uidmItem.PLATING_THICKNESS1_1;
            dtoItem.PLATING_THICKNESS1_2 = uidmItem.PLATING_THICKNESS1_2;
            dtoItem.PLATING_THICKNESS2_1 = uidmItem.PLATING_THICKNESS2_1;
            dtoItem.PLATING_THICKNESS2_2 = uidmItem.PLATING_THICKNESS2_2;
            dtoItem.PLATING_KTC          = uidmItem.PLATING_KTC;
            dtoItem.BAKING_FLAG          = uidmItem.BAKING_FLAG;
            dtoItem.BAKING_TIME          = uidmItem.BAKING_TIME;
            dtoItem.BAKING_TEMP          = uidmItem.BAKING_TEMP;

            #endregion

            #region Other Tab

            dtoItem.OTHER_TREATMENT1_FLAG      = uidmItem.OTHER_TREATMENT1_FLAG;
            dtoItem.OTHER_TREATMENT1_KIND      = uidmItem.OTHER_TREATMENT1_KIND;
            dtoItem.OTHER_TREATMENT1_CONDITION = uidmItem.OTHER_TREATMENT1_CONDITION;
            dtoItem.OTHER_TREATMENT2_FLAG      = uidmItem.OTHER_TREATMENT2_FLAG;
            dtoItem.OTHER_TREATMENT2_KIND      = uidmItem.OTHER_TREATMENT2_KIND;
            dtoItem.OTHER_TREATMENT2_CONDITION = uidmItem.OTHER_TREATMENT2_CONDITION;

            #endregion

            dtoItem.OLD_DATA = new NZInt(null, 0);

            //ItemProcessDTO dtoItemProcess = new ItemProcessDTO();
            //dtoItemProcess.ITEM_CD = uidmItem.ITEM_CD;
            //dtoItemProcess.CRT_BY = CommonLib.Common.CurrentUserInfomation.UserCD;
            //dtoItemProcess.CRT_DATE.Value = CommonLib.Common.GetDatabaseDateTime();
            //dtoItemProcess.CRT_MACHINE = CommonLib.Common.CurrentUserInfomation.Machine;
            //dtoItemProcess.UPD_BY = CommonLib.Common.CurrentUserInfomation.UserCD;
            //dtoItemProcess.UPD_DATE.Value = CommonLib.Common.GetDatabaseDateTime();
            //dtoItemProcess.UPD_MACHINE = CommonLib.Common.CurrentUserInfomation.Machine;

            #endregion

            List <ItemProcessDTO> listNew          = new List <ItemProcessDTO>();
            List <BOMDTO>         listNewComponent = new List <BOMDTO>();
            List <ItemMachineDTO> listNewMachine   = new List <ItemMachineDTO>();

            //Add
            uidmItem.DataView.AcceptChanges();
            uidmItem.DataComponentView.AcceptChanges();

            #region Routing

            DataTable dtNew = uidmItem.DataView;
            if (dtNew != null)
            {
                foreach (DataRow dr in dtNew.Rows)
                {
                    ItemProcessDTO dto = new ItemProcessDTO();

                    dto.CRT_BY              = CommonLib.Common.CurrentUserInfomation.UserCD;
                    dto.CRT_MACHINE         = CommonLib.Common.CurrentUserInfomation.Machine;
                    dto.UPD_BY              = CommonLib.Common.CurrentUserInfomation.UserCD;
                    dto.UPD_MACHINE         = CommonLib.Common.CurrentUserInfomation.Machine;
                    dto.ITEM_CD             = uidmItem.ITEM_CD;
                    dto.ITEM_SEQ            = new NZInt(null, dr[(int)ItemViewProcessDTO.eColumns.ITEM_SEQ]);
                    dto.PROCESS_CD          = new NZString(null, dr[(int)ItemViewProcessDTO.eColumns.PROCESS_CD]);
                    dto.WEIGHT              = new NZDecimal(null, dr[(int)ItemViewProcessDTO.eColumns.WEIGHT]);
                    dto.PRODUCTION_LEADTIME = new NZInt(null, dr[(int)ItemViewProcessDTO.eColumns.PRODUCTION_LEADTIME]);
                    dto.QTY_PER_DAY         = new NZDecimal(null, dr[(int)ItemViewProcessDTO.eColumns.QTY_PER_DAY]);
                    dto.SUPPLIER_CD         = new NZString(null, dr[(int)ItemViewProcessDTO.eColumns.SUPPLIER_CD]);
                    dto.OLD_DATA            = new NZInt(null, 0);


                    listNew.Add(dto);
                }
            }

            ////Edit
            //DataTable dtEdit = uidmItem.DataView.GetChanges(DataRowState.Modified);
            //if (dtEdit != null)
            //{
            //    foreach (DataRow dr in dtEdit.Rows)
            //    {
            //        ItemProcessDTO dto = new ItemProcessDTO();
            //        //dto.CRT_BY = CommonLib.Common.CurrentUserInfomation.UserCD;
            //        //dto.CRT_MACHINE = CommonLib.Common.CurrentUserInfomation.Machine;
            //        dto.UPD_BY = CommonLib.Common.CurrentUserInfomation.UserCD;
            //        dto.UPD_MACHINE = CommonLib.Common.CurrentUserInfomation.Machine;
            //        dto.ITEM_CD = new NZInt(null, Convert.ToInt32(uidmItem.ITEM_CD.StrongValue));
            //        dto.ITEM_SEQ = new NZInt(null, dr[(int)ItemViewProcessDTO.eColumns.ITEM_SEQ]);
            //        dto.PROCESS_CD = new NZString(null, dr[(int)ItemViewProcessDTO.eColumns.PROCESS_CD]);
            //        dto.PROCESS_CD = new NZString(null, dr[(int)ItemViewProcessDTO.eColumns.PROCESS_NAME]);
            //        dto.WEIGHT = new NZDecimal(null, dr[(int)ItemViewProcessDTO.eColumns.WEIGHT]);
            //        dto.PRODUCTION_LEADTIME = new NZInt(null, dr[(int)ItemViewProcessDTO.eColumns.PRODUCTION_LEADTIME]);
            //        dto.QTY_PER_DAY = new NZDecimal(null, dr[(int)ItemViewProcessDTO.eColumns.QTY_PER_DAY]);
            //        dto.SUPPLIER_CD = new NZString(null, dr[(int)ItemViewProcessDTO.eColumns.SUPPLIER_CD]);
            //        dto.OLD_DATA = new NZInt(null, 0);

            //        listEdit.Add(dto);
            //    }
            //}

            ////delete
            //DataTable dtDelete = uidmItem.DataView.GetChanges(DataRowState.Deleted);
            //if (dtDelete != null)
            //{
            //    listDelete = DTOUtility.ConvertDataTableToList<ItemProcessDTO>(dtDelete);

            //    for (int i = 0; i < listDelete.Count; i++)
            //    {
            //        listDelete[i].ITEM_CD = new NZInt(null, Convert.ToInt32(uidmItem.ITEM_CD.StrongValue));
            //    }

            //}

            #endregion

            #region Component

            int       iComponet_Seq  = 0;
            DataTable dtNewComponent = uidmItem.DataComponentView;//.GetChanges(DataRowState.Added);
            if (dtNewComponent != null)
            {
                foreach (DataRow dr in dtNewComponent.Rows)
                {
                    iComponet_Seq = iComponet_Seq + 1;
                    BOMDTO dto = new BOMDTO();
                    dto.CRT_BY        = CommonLib.Common.CurrentUserInfomation.UserCD;
                    dto.CRT_MACHINE   = CommonLib.Common.CurrentUserInfomation.Machine;
                    dto.UPD_BY        = CommonLib.Common.CurrentUserInfomation.UserCD;
                    dto.UPD_MACHINE   = CommonLib.Common.CurrentUserInfomation.Machine;
                    dto.UPPER_ITEM_CD = uidmItem.ITEM_CD;
                    dto.LOWER_ITEM_CD = new NZString(null, dr[(int)ItemComponentDTO.eColumns.ITEM_CD]);
                    dto.ITEM_SEQ      = new NZInt(null, iComponet_Seq);
                    dto.UPPER_QTY     = new NZDecimal(null, dr[(int)ItemComponentDTO.eColumns.PCS]);
                    dto.LOWER_QTY     = new NZDecimal(null, 1);
                    dto.OLD_DATA      = new NZInt(null, 0);

                    listNewComponent.Add(dto);
                }
            }
            //DataTable dtEditComponent = uidmItem.DataView.GetChanges(DataRowState.Modified);
            //if (dtEditComponent != null)
            //{
            //    foreach (DataRow dr in dtEditComponent.Rows)
            //    {
            //        BOMDTO dto = new BOMDTO();
            //        dto.CRT_BY = CommonLib.Common.CurrentUserInfomation.UserCD;
            //        dto.CRT_MACHINE = CommonLib.Common.CurrentUserInfomation.Machine;
            //        dto.UPD_BY = CommonLib.Common.CurrentUserInfomation.UserCD;
            //        dto.UPD_MACHINE = CommonLib.Common.CurrentUserInfomation.Machine;
            //        dto.UPPER_ITEM_CD = uidmItem.ITEM_CD;
            //        dto.LOWER_ITEM_CD = new NZString(null, dr[(int)ItemComponentDTO.eColumns.ITEM_CD]);
            //        dto.ITEM_SEQ = new NZInt(null, iComponet_Seq);
            //        dto.UPPER_QTY = new NZDecimal(null, dr[(int)ItemComponentDTO.eColumns.PCS]);
            //        dto.LOWER_QTY = new NZDecimal(null, 1);
            //        dto.OLD_DATA = new NZInt(null, 0);


            //        listEditComponent.Add(dto);
            //    }
            //}

            //DataTable dtDeleteComponent = uidmItem.DataView.GetChanges(DataRowState.Deleted);
            //if (dtDeleteComponent != null)
            //{
            //    List<ItemComponentDTO> list = DTOUtility.ConvertDataTableToList<ItemComponentDTO>(dtDeleteComponent);

            //    for (int i = 0; i < list.Count; i++)
            //    {
            //        BOMDTO dto = new BOMDTO();
            //        dto.UPPER_ITEM_CD = uidmItem.ITEM_CD;
            //        dto.LOWER_ITEM_CD = new NZString(null, list[i].ITEM_CD);
            //        dto.ITEM_SEQ = new NZInt(null, iComponet_Seq);
            //        listDeleteComponent.Add(dto);
            //    }
            //}

            #endregion

            #region Item Machine

            DataTable dtItemMachine = uidmItem.DataItemMachine;
            if (dtItemMachine != null)
            {
                int iRunNo = 0;
                foreach (DataRow dr in dtItemMachine.Rows)
                {
                    iRunNo = iRunNo + 1;
                    ItemMachineDTO dto = new ItemMachineDTO();
                    dto.CRT_BY          = CommonLib.Common.CurrentUserInfomation.UserCD;
                    dto.CRT_MACHINE     = CommonLib.Common.CurrentUserInfomation.Machine;
                    dto.UPD_BY          = CommonLib.Common.CurrentUserInfomation.UserCD;
                    dto.UPD_MACHINE     = CommonLib.Common.CurrentUserInfomation.Machine;
                    dto.ITEM_CD         = uidmItem.ITEM_CD;
                    dto.RUN_NO          = new NZInt(null, iRunNo);
                    dto.MACHINE_PROCESS = new NZString(null, dr[(int)ItemMachineDTO.eColumns.MACHINE_PROCESS]);
                    dto.MACHINE_TYPE    = new NZString(null, dr[(int)ItemMachineDTO.eColumns.MACHINE_TYPE]);
                    dto.OLD_DATA        = new NZInt(null, 0);
                    listNewMachine.Add(dto);
                }
            }

            #endregion

            ItemBIZ biz = new ItemBIZ();
            biz.AddNew(dtoItem, listNew, listNewComponent, listNewMachine);
            //biz.UpdateWithoutPK(dtoItem, listNew, listEdit, listDelete, listNewComponent, listEditComponent, listDeleteComponent);
        }