コード例 #1
0
ファイル: TemplateDetLayer.cs プロジェクト: JuhaSoft/BOM_MOI
        public bool InSertTplDet(TemplateDetModel model)
        {
            try
            {
                ExecuteCommand(cn =>
                {
                    MySqlCommand cmd = new MySqlCommand(@"Insert Into tbltemplatedet   (tplHDGUID,pgGUID)
                                                        values(@tplHDGUID,@pgGUID)", cn);
                    cmd.Parameters.AddWithValue("@tplHDGUID", model.tplHDGUID);
                    cmd.Parameters.AddWithValue("@pgGUID", model.pgGUID);

                    rst = cmd.ExecuteNonQuery();

                });
                if (rst == 1)
                    return true;
                else
                    return false;

            }
            catch (Exception)
            {

                throw;
            }
        }
コード例 #2
0
        private void Btn_Save_Click(object sender, EventArgs e)
        {
            string usr = _frmMain.activeuser;
            if (StatusEdit == false)
            {
                if (!validasiTextBox())
                {
                    return;
                }
                if (layertplHead.GetValTpl(txt_Name.Text))
                {
                    var exceptionMessage = "template already exist";
                    // clsWin.ClearWindowsObJect(panelEx1);
                    clsWin.ErrorMessage((exceptionMessage).ToString(), "Oops");
                    txt_Name.Focus();
                    return;
                }

                TemplateHeadModel TplHeader;
                TemplateDetModel TplDet;

                try
                {

                    {
                            TplHeader = new TemplateHeadModel()
                            {
                                tplGUID = Guid.NewGuid().ToString(),
                                tplName = txt_Name.Text,
                                Comp = clsWin.GetComputerName(),
                                UserName = usr,
                                LastUpdate = DateTime.Now
                            };
                            layertplHead.InSertTpl(TplHeader);
                            Cursor.Current = Cursors.WaitCursor;

                            for (int i = 0; i <= dgViewGroup.RowCount - 1; i++)
                            {

                                 if(int.Parse( dgViewGroup.Rows[i].Cells[3].Value.ToString())==1)
                                {
                                     TplDet = new TemplateDetModel()
                                    {
                                        tplHDGUID=TplHeader.tplGUID,
                                        pgGUID=dgViewGroup.Rows[i].Cells[0].Value.ToString()

                                    };
                                    layerTplDet.InSertTplDet(TplDet);

                                }

                           }
                            clsWin.SuccessMessage("Template has been saved", "Success");
                            tplTemplateGUID = "";
                            loadAllDataGroup();
                            getListDataTpl();
                            txt_Name.Text="";

                     }
                }

                catch (DbEntityValidationException ex)
                {

                    var errorMessages = ex.EntityValidationErrors
                                .SelectMany(x => x.ValidationErrors)
                                .Select(x => x.ErrorMessage);
                            var exceptionMessage = string.Concat(errorMessages);
                            clsWin.ClearWindowsObJect(panelEx1);
                            clsWin.ErrorMessage((exceptionMessage).ToString(), "Oops");
                }
             }
             else
            {
                if (!validasiTextBox())
                {
                    return;
                }

                TemplateHeadModel TplHeader;
                TemplateDetModel TplDet;

                try
                {

                    {
                        TplHeader = new TemplateHeadModel()
                        {
                            tplGUID = tplTemplateGUID,
                            tplName = txt_Name.Text,
                            Comp = clsWin.GetComputerName(),
                            UserName = usr,
                            LastUpdate = DateTime.Now
                        };
                        layertplHead.UpdatetTpl(TplHeader, tplTemplateGUID);
                        Cursor.Current = Cursors.WaitCursor;
                        layerTplDet.DeleteBefEdit(tplTemplateGUID);

                            for (int i = 0; i <= dgViewGroup.RowCount - 1; i++)
                            {
                                int val = dgViewGroup.Rows[i].Cells[3].Value.ToString() == "" ? 0 : 1;
                                if (val == 1)
                                {
                                     TplDet = new TemplateDetModel()
                                    {
                                        tplHDGUID=tplTemplateGUID,
                                        pgGUID=dgViewGroup.Rows[i].Cells[0].Value.ToString()

                                    };
                                    layerTplDet.InSertTplDet(TplDet);
                                    //TplDet.tplHDGUID = TplHeader.tplGUID,
                                    //TplDet.pgGUID = (dgViewGroup.Rows[i].Cells[0].Value.ToString())
                                }

                           }
                            clsWin.SuccessMessage("Template has been Edit", "Success");
                            tplTemplateGUID = "";
                            loadAllDataGroup();
                            getListDataTpl();
                            txt_Name.Text="";

                     }
                }

                catch (DbEntityValidationException ex)
                {

                    var errorMessages = ex.EntityValidationErrors
                                .SelectMany(x => x.ValidationErrors)
                                .Select(x => x.ErrorMessage);
                            var exceptionMessage = string.Concat(errorMessages);
                            clsWin.ClearWindowsObJect(panelEx1);
                            clsWin.ErrorMessage((exceptionMessage).ToString(), "Oops");
                }

            }

            StatusEdit = false;
            txt_Name.ReadOnly = true;
            loadAllDataGroup();
        }