Esempio n. 1
0
        public static string InsertDepartment(LDepartment pitems)
        {
            int   i        = 0;
            Query _QueryRS = LDepartment.CreateQuery();

            try
            {
                if (!LDepartment.FetchByParameter(LDepartment.Columns.Id, Comparison.Equals, pitems.Id).Read())
                {
                    pitems.IsNew = true;
                    pitems.Save(i);
                    return(_QueryRS.GetMax(LDepartment.Columns.Id).ToString());
                    //var dt =
                    //    new Select(LDepartment.Columns.Id).From(LDepartment.Schema.Name).Where(LDepartment.Columns.IPAddress).IsEqualTo
                    //        (pitems.IPAddress).ExecuteDataSet().Tables[0];
                    //return dt.Rows [0][0].ToString();
                    //.ExecuteDataSet().Tables[0].Rows[0][0].ToString();
                }
                else
                {
                    return("-1");
                    //throw new Exception(string.Format("Name:{0} Đã tồn tại", pitems.IPAddress));
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Esempio n. 2
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                txtID.Text = txtID.Text.ToUpper();
                if (ValidData())
                {
                    switch (vAction)
                    {
                    case action.Insert:
                        var obj = new LDepartment();
                        obj.SName = Utility.sDbnull(txtName.Text);
                        obj.SDesc = Utility.sDbnull(txtDesc.Text);
                        obj.IsNew = true;
                        obj.Save();

                        drList = dtList.NewRow();
                        drList[LDepartment.Columns.Id] = LDepartment.CreateQuery().GetMax(LDepartment.Columns.Id);
                        ApplyData2Datarow();
                        dtList.Rows.InsertAt(drList, 0);
                        dtList.AcceptChanges();

                        txtID.Text = Utility.sDbnull(drList[LDepartment.Columns.Id]);
                        vAction    = action.Update;
                        break;

                    case action.Update:
                        new Update(LDepartment.Schema.Name).Set(LDepartment.Columns.SName).EqualTo(txtName.Text).
                        Set(LDepartment.Columns.SDesc).EqualTo(txtDesc.Text).
                        Where(LDepartment.Columns.Id).IsEqualTo(Utility.Int32Dbnull(txtID.Text)).
                        Execute();
                        ApplyData2Datarow();
                        drList.AcceptChanges();
                        break;
                    }
                }
            }
            catch (Exception ex)
            {
                Utility.ShowMsg(ex.Message);
            }
        }