Beispiel #1
0
 private void btnAddValue_Click(object sender, EventArgs e)
 {
     _isAddValue  = true;
     txtName.Text = "";
     _model       = new MaterialParameterValueModel();
     SetInterfaceValue(true);
 }
Beispiel #2
0
        private void btnEditValue_Click(object sender, EventArgs e)
        {
            if (grvValue.FocusedRowHandle < 0)
            {
                return;
            }
            _isAddValue = false;
            int iD = TextUtils.ToInt(grvValue.GetFocusedRowCellValue(colIDValue));

            _model        = (MaterialParameterValueModel)MaterialParameterValueBO.Instance.FindByPK(iD);
            txtValue.Text = _model.ParaValue;
            SetInterfaceValue(true);
        }
 protected MaterialParameterValueFacade(MaterialParameterValueModel model) : base(model)
 {
 }
Beispiel #4
0
        void Save()
        {
            //ProcessTransaction pt = new ProcessTransaction();
            //pt.OpenConnection();
            //pt.BeginTransaction();
            using (WaitDialogForm fWait = new WaitDialogForm("Vui lòng chờ trong giây lát", "Đang tạo thông số vật tư"))
            {
                try
                {
                    string             parentGroupCode = Path.GetFileNameWithoutExtension(btnBrowse.Text);
                    ArrayList          listGroup       = MaterialGroupBO.Instance.FindByAttribute("Code", parentGroupCode);
                    MaterialGroupModel parentGroup     = (MaterialGroupModel)listGroup[0];
                    string             currentGroup    = "TPAVT." + cboSheet.SelectedValue.ToString().Split('-')[0].Trim();

                    #region Material Group
                    MaterialGroupModel thisGroup;
                    if (!MaterialGroupBO.Instance.CheckExist("Code", currentGroup))
                    {
                        thisGroup             = new MaterialGroupModel();
                        thisGroup.Code        = currentGroup;
                        thisGroup.Name        = cboSheet.SelectedValue.ToString().Split('-')[1].Trim();
                        thisGroup.CreatedDate = TextUtils.GetSystemDate();
                        thisGroup.CreatedBy   = Global.AppUserName;
                        thisGroup.UpdatedDate = thisGroup.CreatedDate;
                        thisGroup.UpdatedBy   = Global.AppUserName;
                        //thisGroup.ID = (int)pt.Insert(thisGroup);
                        thisGroup.ID = (int)MaterialGroupBO.Instance.Insert(thisGroup);
                    }
                    else
                    {
                        thisGroup = (MaterialGroupModel)MaterialGroupBO.Instance.FindByAttribute("Code", currentGroup)[0];
                    }
                    #endregion Material Group

                    //List<MaterialParameterValueModel> listTemParaValue = new List<MaterialParameterValueModel>();

                    for (int i = 0; i < grvData.RowCount; i++)
                    {
                        if (i == 0)
                        {
                            for (int j = 4; j < grvData.Columns.Count; j++)
                            {
                                #region Thêm thông số kỹ thuật
                                if (grvData.GetRowCellValue(i, "F" + (j + 1)) == null)
                                {
                                    continue;
                                }
                                string thisNameTS = grvData.GetRowCellValue(i, "F" + (j + 1)).ToString().Trim();
                                if (thisNameTS == "")
                                {
                                    continue;
                                }

                                DataTable dtTS = TextUtils.Select(string.Format("Select * from MaterialParameters with(nolock) where Name=N'{0}' and MaterialGroupID ={1}", thisNameTS, thisGroup.ID));
                                MaterialParametersModel modelTSVT = null;
                                if (dtTS.Rows.Count == 0)
                                {
                                    modelTSVT                 = new MaterialParametersModel();
                                    modelTSVT.Name            = thisNameTS;
                                    modelTSVT.MaterialGroupID = thisGroup.ID;
                                    //modelTSVT.ID = (int)pt.Insert(modelTSVT);
                                    modelTSVT.ID = (int)MaterialParametersBO.Instance.Insert(modelTSVT);
                                }
                                #endregion Thông số kỹ thuật
                            }
                        }
                        else
                        {
                            if (grvData.GetRowCellValue(i, "F2") == null)
                            {
                                continue;
                            }
                            string materialCode = grvData.GetRowCellValue(i, "F2").ToString().Trim();
                            if (materialCode == "")
                            {
                                continue;
                            }

                            #region Check Customer
                            string        customerCode = grvData.GetRowCellValue(i, "F4").ToString().Trim();
                            CustomerModel thisCustomer = null;
                            if (!CustomerBO.Instance.CheckExist("Code", customerCode))
                            {
                                thisCustomer      = new CustomerModel();
                                thisCustomer.Code = customerCode.ToUpper();
                                thisCustomer.Name = customerCode.ToUpper();
                                //thisCustomer.ID = (int)pt.Insert(thisCustomer);
                                thisCustomer.ID = (int)CustomerBO.Instance.Insert(thisCustomer);
                                if (!DocUtils.CheckExits("Datasheet" + "/" + customerCode.ToUpper()))
                                {
                                    DocUtils.MakeDir("Datasheet" + "/" + customerCode.ToUpper());
                                }
                            }
                            else
                            {
                                thisCustomer = (CustomerModel)CustomerBO.Instance.FindByAttribute("Code", customerCode)[0];
                            }
                            #endregion Check Customer

                            #region Check Material
                            MaterialModel thisMaterial;
                            string        materialName = grvData.GetRowCellValue(i, "F3").ToString().Trim();
                            if (!MaterialBO.Instance.CheckExist("Code", materialCode))
                            {
                                thisMaterial                 = new MaterialModel();
                                thisMaterial.Code            = materialCode;
                                thisMaterial.Name            = materialName;
                                thisMaterial.CustomerID      = thisCustomer.ID;
                                thisMaterial.MaterialGroupID = thisGroup.ID;
                                //thisMaterial.ID = (int)pt.Insert(thisMaterial);
                                thisMaterial.ID = (int)MaterialBO.Instance.Insert(thisMaterial);
                            }
                            else
                            {
                                thisMaterial = (MaterialModel)MaterialBO.Instance.FindByAttribute("Code", materialCode)[0];
                            }
                            #endregion Check Material

                            for (int j = 4; j < grvData.Columns.Count; j++)
                            {
                                if (grvData.GetRowCellValue(i, "F" + (j + 1)) == null)
                                {
                                    continue;
                                }
                                string thisTSName = grvData.GetRowCellValue(0, "F" + (j + 1)).ToString().Trim();
                                if (thisTSName == "")
                                {
                                    continue;
                                }

                                //MaterialParametersModel modelTSVT = (MaterialParametersModel)MaterialParametersBO.Instance.
                                //    FindByExpression(new Expression("Name", thisTSName).And(new Expression("MaterialGroupID", thisGroup.ID)))[0];
                                DataTable dtTSKT = TextUtils.Select(string.Format("select * from  MaterialParameters where Name = N'{0}' and MaterialGroupID = {1}", thisTSName, thisGroup.ID));
                                if (dtTSKT.Rows.Count == 0)
                                {
                                    continue;
                                }
                                #region MaterialParameterLink
                                MaterialParameterLinkModel link = null;
                                DataTable dtlink = TextUtils.Select(string.
                                                                    Format("Select * from MaterialParameterLink with(nolock) where MaterialParameterID={0} and MaterialID ={1}", TextUtils.ToInt(dtTSKT.Rows[0]["ID"]), thisMaterial.ID));
                                if (dtlink.Rows.Count == 0)
                                {
                                    link                     = new MaterialParameterLinkModel();
                                    link.MaterialID          = thisMaterial.ID;
                                    link.MaterialParameterID = TextUtils.ToInt(dtTSKT.Rows[0]["ID"]);//modelTSVT.ID;
                                    //link.ID = (int)pt.Insert(link);
                                    link.ID = (int)MaterialParameterLinkBO.Instance.Insert(link);
                                }
                                else
                                {
                                    //link = (MaterialParameterLinkModel)MaterialParameterLinkBO.Instance.FindByPK(TextUtils.ToInt(dtlink.Rows[0]["ID"]));
                                }
                                #endregion MaterialParameterLink

                                string value = grvData.GetRowCellValue(i, "F" + (j + 1)) == null ? "" : grvData.GetRowCellValue(i, "F" + (j + 1)).ToString().Trim();
                                value = value.Trim().Replace("\n", ",").Replace("_", "-");
                                if (value != "")
                                {
                                    #region MaterialParameterValue
                                    MaterialParameterValueModel paraValue = null;
                                    DataTable dtParameterValue            = TextUtils.Select(string.
                                                                                             Format("Select * from MaterialParameterValue with(nolock) where MaterialParameterID={0} and REPLACE(ParaValue,' ','') =N'{1}'",
                                                                                                    TextUtils.ToInt(dtTSKT.Rows[0]["ID"]), value.Replace(" ", "")));
                                    if (dtParameterValue.Rows.Count == 0)
                                    {
                                        paraValue = new MaterialParameterValueModel();
                                        paraValue.MaterialParameterID = TextUtils.ToInt(dtTSKT.Rows[0]["ID"]);//modelTSVT.ID;
                                        paraValue.ParaValue           = value;
                                        //paraValue.ID = (int)pt.Insert(paraValue);
                                        paraValue.ID = (int)MaterialParameterValueBO.Instance.Insert(paraValue);
                                    }
                                    else
                                    {
                                        paraValue = (MaterialParameterValueModel)MaterialParameterValueBO.Instance.FindByPK(TextUtils.ToInt(dtParameterValue.Rows[0]["ID"]));
                                    }

                                    #endregion MaterialParameterValue

                                    #region MaterialConnect
                                    MaterialConnectModel connect   = null;
                                    DataTable            dtConnect = TextUtils.Select(string.
                                                                                      Format("Select * from MaterialConnect with(nolock) where MaterialParameterID={0} and MaterialID ={1} and MaterialParameterValueID={2}",
                                                                                             TextUtils.ToInt(dtTSKT.Rows[0]["ID"]), thisMaterial.ID, paraValue.ID));
                                    if (dtConnect.Rows.Count == 0)
                                    {
                                        connect = new MaterialConnectModel();
                                        connect.MaterialParameterID      = TextUtils.ToInt(dtTSKT.Rows[0]["ID"]);//modelTSVT.ID;
                                        connect.MaterialID               = thisMaterial.ID;
                                        connect.MaterialParameterValueID = paraValue.ID;
                                        //connect.ID = (int)pt.Insert(connect);
                                        connect.ID = (int)MaterialConnectBO.Instance.Insert(connect);
                                    }

                                    #endregion MaterialConnect
                                }
                            }
                        }
                    }

                    //pt.CommitTransaction();
                    MessageBox.Show("Thành công!");
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, TextUtils.Caption, MessageBoxButtons.OK, MessageBoxIcon.Stop);
                }
                finally
                {
                    //pt.CloseConnection();
                }
            }
        }