예제 #1
0
 protected void btnAdd_Click(object sender, EventArgs e)
 {
     if (HelperUtility.hasPurviewOP("SalesCompany_add"))
     {
         ModelSalesCompany model;
         StringBuilder     objSB = new StringBuilder();
         if ("".Equals(tbCompanyName.Value.Trim()))
         {
             return;
         }
         objSB.Append(tbCompanyName.Value.Trim());
         // 获取文本框文本根据换行符分割成字符串数组
         string[] aryRows = objSB.ToString().Split(Environment.NewLine.ToCharArray());
         aryRows = HelperUtility.removeArrayBlankRow(aryRows);
         if (aryRows.Length <= 0)
         {
             return;
         }
         for (int i = 0; i < aryRows.Length; i++)
         {
             model          = new ModelSalesCompany();
             model.name     = aryRows[i];
             model.id_admin = (int)ViewState["AdminId"];
             BllSalesCompany.add(model);
         }
         HelperUtility.showAlert("添加成功!", "list.aspx");
     }
     else
     {
         string strUrl = "list.aspx?page=" + ViewState["page"];
         HelperUtility.showAlert("没有添加权限", strUrl);
     }
 }
예제 #2
0
        public static int add(ModelSalesCompany model)
        {
            string strSQL = @"
INSERT INTO sales_company (
  name,
  id_admin,
  time_create,
  is_deleted
) VALUES (
  @name,
  @id_admin,
  @time_create,
  @is_deleted
)";

            MySqlParameter[] aryParams = new MySqlParameter[4];
            aryParams[0] = new MySqlParameter("@name", model.name);
            aryParams[1] = new MySqlParameter("@id_admin", model.id_admin);
            aryParams[2] = new MySqlParameter("@time_create", model.time_create);
            aryParams[3] = new MySqlParameter("@is_deleted", model.is_deleted);
            if (HelperMySql.ExecuteNonQuery(strSQL, aryParams) > 0)
            {
                strSQL = "SELECT MAX(id) FROM sales_company";
                object objReturn = HelperMySql.ExecuteScalar(strSQL);
                return(objReturn == null ? 0 : Convert.ToInt32(objReturn));
            }
            else
            {
                return(0);
            }
        }
예제 #3
0
        public static int add(ModelSalesCompany model)
        {
            // 先判断有没有重名
            int intId = getIdByName(model.name);

            if (intId > 0)
            {
                return(intId);
            }
            else
            {
                return(DalSalesCompany.add(model));
            }
        }
예제 #4
0
        protected void gvShow_RowUpdating(object sender, GridViewUpdateEventArgs e)
        {
            string strName = ((TextBox)gvShow.Rows[e.RowIndex].Cells[0].Controls[1]).Text;

            strName = HelperUtility.removeStringSpace(strName.Trim());
            if (!"".Equals(strName))
            {
                int intId = Convert.ToInt32(gvShow.DataKeys[e.RowIndex].Value);
                ModelSalesCompany model = BllSalesCompany.getById(intId);
                model.name = strName;
                BllSalesCompany.update(model);
                gvShow.EditIndex = -1;
                LoadDataPage();
            }
        }
예제 #5
0
        public static ModelSalesCompany getById(int intId)
        {
            string strSQL = @"SELECT * FROM sales_company WHERE id = @id";

            MySqlParameter[] aryParams = new MySqlParameter[1];
            aryParams[0] = new MySqlParameter("@id", intId);
            DataTable objDT = HelperMySql.GetDataTable(strSQL, aryParams);

            if (objDT == null || objDT.Rows.Count <= 0)
            {
                return(null);
            }
            ModelSalesCompany model = new ModelSalesCompany();

            model.id          = Convert.ToInt32(objDT.Rows[0]["id"]);
            model.name        = Convert.ToString(objDT.Rows[0]["name"]);
            model.id_admin    = Convert.ToInt32(objDT.Rows[0]["id_admin"]);
            model.time_create = Convert.ToDateTime(objDT.Rows[0]["time_create"]);
            model.is_deleted  = Convert.ToInt32(objDT.Rows[0]["is_deleted"]);
            return(model);
        }
예제 #6
0
        public static int update(ModelSalesCompany model)
        {
            string strSQL = @"
UPDATE sales_company
SET
  name = @name,
  id_admin = @id_admin,
  time_create = @time_create,
  is_deleted = @is_deleted
WHERE
    id = @id
";

            MySqlParameter[] aryParams = new MySqlParameter[5];
            aryParams[0] = new MySqlParameter("@name", model.name);
            aryParams[1] = new MySqlParameter("@id_admin", model.id_admin);
            aryParams[2] = new MySqlParameter("@time_create", model.time_create);
            aryParams[3] = new MySqlParameter("@is_deleted", model.is_deleted);
            aryParams[4] = new MySqlParameter("@id", model.id);
            return(HelperMySql.ExecuteNonQuery(strSQL, aryParams));
        }
예제 #7
0
        // 此方法有二个参数,根据名称查找id,用在添加入库单页面上
        // 如果已经添加了这个公司则直接返回id,如果没加则新建销售公司
        public static int getIdByName(string strCompanyName, int intAdminId)
        {
            int intId = getIdByName(strCompanyName);

            if (intId > 0)
            {
                return(intId);
            }
            ModelSalesCompany model = new ModelSalesCompany();

            model.name     = strCompanyName;
            model.id_admin = intAdminId;
            intId          = DalSalesCompany.add(model);
            if (intId > 0)
            {
                return(intId);
            }
            else
            {
                return(0);
            }
        }
예제 #8
0
 public static int update(ModelSalesCompany model)
 {
     return(DalSalesCompany.update(model));
 }