private void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                txtID.Text = txtID.Text.ToUpper();
                LManufacture objManufacture;
                if (ValidData())
                {
                    switch (txtID.Text)
                    {
                    case "-1":
                        var obj = new LManufacture();
                        obj.SName = Utility.sDbnull(txtName.Text);
                        obj.SDesc = Utility.sDbnull(txtDesc.Text);
                        obj.IsNew = true;
                        obj.Save();

                        txtID.Text     = Utility.sDbnull(LManufacture.CreateQuery().GetMax(LManufacture.Columns.Id));
                        objManufacture = LManufacture.FetchByID(Utility.Int32Dbnull(txtID.Text, -1));
                        if (objManufacture != null)
                        {
                            DataRow newDr = dtList.NewRow();
                            Utility.FromObjectToDatarow(objManufacture, ref newDr);
                            dtList.Rows.Add(newDr);
                        }
                        break;

                    default:
                        new Update(LManufacture.Schema.Name).Set(LManufacture.Columns.SName).EqualTo(txtName.Text).
                        Set(LManufacture.Columns.SDesc).EqualTo(txtDesc.Text).
                        Where(LManufacture.Columns.Id).IsEqualTo(Utility.Int32Dbnull(txtID.Text)).
                        Execute();
                        objManufacture = LManufacture.FetchByID(Utility.Int32Dbnull(txtID.Text, -1));
                        if (objManufacture != null)
                        {
                            DataRow newDr = Utility.GetDataRow(dtList, LManufacture.Columns.Id, objManufacture.Id);
                            Utility.FromObjectToDatarow(objManufacture, ref newDr);
                            newDr.AcceptChanges();
                        }

                        break;
                    }
                }
            }
            catch (Exception ex)
            {
                Utility.ShowMsg(ex.Message);
            }
        }
Beispiel #2
0
        /// <summary>
        /// Hàm Insert dữ liệu vào bảng Manufacture
        /// </summary>
        /// <param name="pitems"></param>
        /// <returns></returns>
        public static string InsertManufacture(LManufacture pitems)
        {
            int   i       = 0;
            Query queryRs = LManufacture.CreateQuery();

            try
            {
                if (!LManufacture.FetchByParameter(LManufacture.Columns.Id, Comparison.Equals, pitems.Id).Read())
                {
                    pitems.IsNew = true;
                    pitems.Save(i);
                    return(queryRs.GetMax(LManufacture.Columns.Id).ToString());
                }
                else
                {
                    return("-1");
                    //throw new Exception(string.Format("Name:{0} Đã tồn tại", pitems.IPAddress));
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }