Exemple #1
0
 /// <summary>
 /// get table record
 /// <summary>
 /// <param name=assetid>assetid</param>
 /// <param name=accname>accname</param>
 /// <param name=out emsg>return error message</param>
 ///<returns>get a record detail of assetworkqty</returns>
 public modAssetWorkQty GetItem(string assetid, string accname, out string emsg)
 {
     try
     {
         //Execute a query to read the categories
         string sql = string.Format("select a.asset_id,b.asset_name,a.acc_name,a.work_qty,a.remark,a.update_user,a.update_time from asset_work_qty a inner join asset_list b on a.asset_id=b.asset_id where a.asset_id='{0}' and a.acc_name='{1}' order by a.asset_id,a.acc_name", assetid, accname);
         using (SqlDataReader rdr = SqlHelper.ExecuteReader(sql))
         {
             if (rdr.Read())
             {
                 modAssetWorkQty model = new modAssetWorkQty();
                 model.AssetId    = dalUtility.ConvertToString(rdr["asset_id"]);
                 model.AssetName  = dalUtility.ConvertToString(rdr["asset_name"]);
                 model.AccName    = dalUtility.ConvertToString(rdr["acc_name"]);
                 model.WorkQty    = dalUtility.ConvertToDecimal(rdr["work_qty"]);
                 model.Remark     = dalUtility.ConvertToString(rdr["remark"]);
                 model.UpdateUser = dalUtility.ConvertToString(rdr["update_user"]);
                 model.UpdateTime = dalUtility.ConvertToDateTime(rdr["update_time"]);
                 emsg             = null;
                 return(model);
             }
             else
             {
                 emsg = "Error on read data";
                 return(null);
             }
         }
     }
     catch (Exception ex)
     {
         emsg = dalUtility.ErrorMessage(ex.Message);
         return(null);
     }
 }
Exemple #2
0
 /// <summary>
 /// get all assetworkqty
 /// <summary>
 /// <param name=accname>accname</param>
 /// <param name=out emsg>return error message</param>
 ///<returns>details of all assetworkqty</returns>
 public BindingCollection <modAssetWorkQty> GetIList(out string emsg)
 {
     try
     {
         BindingCollection <modAssetWorkQty> modellist = new BindingCollection <modAssetWorkQty>();
         //Execute a query to read the categories
         string sql = "select a.asset_id,b.asset_name,a.acc_name,a.work_qty,a.remark,a.update_user,a.update_time from asset_work_qty a inner join asset_list b on a.asset_id=b.asset_id order by a.asset_id,a.update_time";
         using (SqlDataReader rdr = SqlHelper.ExecuteReader(sql))
         {
             while (rdr.Read())
             {
                 modAssetWorkQty model = new modAssetWorkQty();
                 model.AssetId    = dalUtility.ConvertToString(rdr["asset_id"]);
                 model.AssetName  = dalUtility.ConvertToString(rdr["asset_name"]);
                 model.AccName    = dalUtility.ConvertToString(rdr["acc_name"]);
                 model.WorkQty    = dalUtility.ConvertToDecimal(rdr["work_qty"]);
                 model.Remark     = dalUtility.ConvertToString(rdr["remark"]);
                 model.UpdateUser = dalUtility.ConvertToString(rdr["update_user"]);
                 model.UpdateTime = dalUtility.ConvertToDateTime(rdr["update_time"]);
                 modellist.Add(model);
             }
         }
         emsg = null;
         return(modellist);
     }
     catch (Exception ex)
     {
         emsg = dalUtility.ErrorMessage(ex.Message);
         return(null);
     }
 }
Exemple #3
0
        public void InitData(modAssetList mod)
        {
            modAssetWorkQty modw = _dal.GetItem(mod.AssetId, Util.modperiod.AccName, out Util.emsg);

            if (modw != null)
            {
                txtAssetId.Text   = modw.AssetId;
                txtAssetName.Text = modw.AssetName;
                txtQty.Text       = modw.WorkQty.ToString();
                txtRemark.Text    = modw.Remark;
                _action           = "EDIT";
            }
            else
            {
                txtAssetId.Text   = mod.AssetId;
                txtAssetName.Text = mod.AssetName;
                _action           = "NEW";
            }
            Status1.Text = _action;
            //Status2.Text = "工量余存:" + mod.LeftQty;
        }
Exemple #4
0
 /// <summary>
 /// update a assetworkqty
 /// <summary>
 /// <param name=assetid>assetid</param>
 /// <param name=accname>accname</param>
 /// <param name=mod>model object of assetworkqty</param>
 /// <param name=out emsg>return error message</param>
 /// <returns>true/false</returns>
 public bool Update(string assetid, string accname, modAssetWorkQty mod, out string emsg)
 {
     try
     {
         string sql = string.Format("update asset_work_qty set work_qty={0},remark='{1}' where asset_id='{2}' and acc_name='{3}'", mod.WorkQty, mod.Remark, assetid, accname);
         int    i   = SqlHelper.ExecuteNonQuery(sql);
         if (i > 0)
         {
             emsg = null;
             return(true);
         }
         else
         {
             emsg = "Unknown error when ExecuteNonQuery!";
             return(false);
         }
     }
     catch (Exception ex)
     {
         emsg = dalUtility.ErrorMessage(ex.Message);
         return(false);
     }
 }
Exemple #5
0
 /// <summary>
 /// insert a assetworkqty
 /// <summary>
 /// <param name=mod>model object of assetworkqty</param>
 /// <param name=out emsg>return error message</param>
 /// <returns>true/false</returns>
 public bool Insert(modAssetWorkQty mod, out string emsg)
 {
     try
     {
         string sql = string.Format("insert into asset_work_qty(asset_id,acc_name,work_qty,remark,update_user,update_time)values('{0}','{1}',{2},'{3}','{4}',getdate())", mod.AssetId, mod.AccName, mod.WorkQty, mod.Remark, mod.UpdateUser);
         int    i   = SqlHelper.ExecuteNonQuery(sql);
         if (i > 0)
         {
             emsg = null;
             return(true);
         }
         else
         {
             emsg = "Unknown error when ExecuteNonQuery!";
             return(false);
         }
     }
     catch (Exception ex)
     {
         emsg = dalUtility.ErrorMessage(ex.Message);
         return(false);
     }
 }
Exemple #6
0
        /// <summary>
        /// get asset depre list
        /// <summary>
        /// <param name=accname>accname</param>
        /// <param name=out emsg>return error message</param>
        ///<returns>get a record detail of assetlist</returns>
        public BindingCollection <modAssetDepreList> GetWaitDepreList(string accname, out string emsg)
        {
            try
            {
                BindingCollection <modAssetDepreList> modellist = new BindingCollection <modAssetDepreList>();
                //Execute a query to read the categories
                string sql = "select asset_id,asset_name,depre_method,raw_qty,raw_mny,(raw_mny-last_mny) ttl_mny,depre_unit from asset_list where status<=1 order by asset_id";
                using (SqlDataReader rdr = SqlHelper.ExecuteReader(sql))
                {
                    while (rdr.Read())
                    {
                        modAssetDepreList model = new modAssetDepreList();
                        model.AccName     = accname;
                        model.AssetId     = dalUtility.ConvertToString(rdr["asset_id"]);
                        model.AssetName   = dalUtility.ConvertToString(rdr["asset_name"]);
                        model.DepreMethod = dalUtility.ConvertToString(rdr["depre_method"]);
                        model.NetMny      = Convert.ToDecimal(rdr["raw_mny"]) - GetDepreMny(model.AssetId, string.Empty);
                        model.DepreUnit   = dalUtility.ConvertToString(rdr["depre_unit"]);

                        switch (model.DepreMethod)
                        {
                        case "平均年限法":
                            model.NetQty = dalUtility.ConvertToDecimal(rdr["raw_qty"]);
                            if (model.NetQty > 0)
                            {
                                model.DepreQty = 1;
                                model.DepreMny = decimal.Round(Convert.ToDecimal(rdr["ttl_mny"]) / model.NetQty, 2);
                            }
                            break;

                        case "双倍余额递减法":
                            model.NetQty = dalUtility.ConvertToDecimal(rdr["raw_qty"]);
                            if (model.NetQty > 0)
                            {
                                model.DepreMny = decimal.Round(Convert.ToDecimal(rdr["ttl_mny"]) * 2 / model.NetQty, 2);
                                if (Convert.ToDecimal(rdr["ttl_mny"]) > 0)
                                {
                                    model.DepreQty = decimal.Round(model.DepreMny * model.NetQty / Convert.ToDecimal(rdr["ttl_mny"]), 2);
                                }
                            }
                            break;

                        case "工作量法":
                            dalAssetWorkQty dalwork = new dalAssetWorkQty();
                            modAssetWorkQty modwork = dalwork.GetItem(model.AssetId, model.AccName, out emsg);
                            if (modwork == null)
                            {
                                emsg = model.AssetName + "未做工量设置";
                                return(null);
                            }
                            else
                            {
                                model.NetQty = dalUtility.ConvertToDecimal(rdr["raw_qty"]);
                                if (model.NetQty > 0)
                                {
                                    model.DepreQty = modwork.WorkQty;
                                    model.DepreMny = decimal.Round(Convert.ToDecimal(rdr["ttl_mny"]) * modwork.WorkQty / model.NetQty, 2);
                                }
                            }
                            break;

                        default:
                            emsg = model.AssetName + "未设置折旧方法";
                            return(null);
                        }
                        if (model.DepreMny > model.NetMny)
                        {
                            model.DepreMny = model.NetMny;
                        }
                        modellist.Add(model);
                    }
                }
                emsg = null;
                return(modellist);
            }
            catch (Exception ex)
            {
                emsg = dalUtility.ErrorMessage(ex.Message);
                return(null);
            }
        }
Exemple #7
0
        private void toolSave_Click(object sender, EventArgs e)
        {
            try
            {
                this.Cursor = Cursors.WaitCursor;
                if (Util.modperiod.LockFlag == 1)
                {
                    MessageBox.Show("该日期的数据已锁定,不能更新数据!", clsTranslate.TranslateString("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }
                dalAccCredenceList dalcre = new dalAccCredenceList();
                if (dalcre.ExistDepre(Util.modperiod.AccName, out Util.emsg))
                {
                    MessageBox.Show("本月已做资产折旧凭证,工作量数据不能更改!", clsTranslate.TranslateString("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }
                if (string.IsNullOrEmpty(txtQty.Text.Trim()))
                {
                    MessageBox.Show(clsTranslate.TranslateString("Work Qty") + clsTranslate.TranslateString(" can not be null!"), clsTranslate.TranslateString("Information"), MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    txtQty.Focus();
                    return;
                }
                else if (!Util.IsNumeric(txtQty.Text))
                {
                    MessageBox.Show(clsTranslate.TranslateString("Work Qty") + clsTranslate.TranslateString(" must be a numeric!"), clsTranslate.TranslateString("Information"), MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    txtQty.Focus();
                    return;
                }
                else if (Convert.ToDecimal(txtQty.Text.Trim()) < 0)
                {
                    MessageBox.Show(clsTranslate.TranslateString("Work Qty") + clsTranslate.TranslateString(" must >= 0!"), clsTranslate.TranslateString("Information"), MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    txtQty.Focus();
                    return;
                }


                modAssetWorkQty mod = new modAssetWorkQty();
                mod.AssetId    = txtAssetId.Text.Trim();
                mod.AssetName  = txtAssetName.Text.Trim();
                mod.AccName    = Util.modperiod.AccName;
                mod.WorkQty    = Convert.ToDecimal(txtQty.Text);
                mod.Remark     = txtRemark.Text.Trim();
                mod.UpdateUser = Util.UserId;
                bool ret;
                if (mod.WorkQty > 0)
                {
                    if (_action == "ADD" || _action == "NEW")
                    {
                        ret = _dal.Insert(mod, out Util.emsg);
                    }
                    else
                    {
                        ret = _dal.Update(mod.AssetId, Util.modperiod.AccName, mod, out Util.emsg);
                    }
                }
                else
                {
                    ret = _dal.Delete(mod.AssetId, Util.modperiod.AccName, out Util.emsg);
                }
                if (ret)
                {
                    this.DialogResult = DialogResult.OK;
                    this.Dispose();
                }
                else
                {
                    MessageBox.Show(Util.emsg, clsTranslate.TranslateString("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, clsTranslate.TranslateString("Information"), MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            finally
            {
                this.Cursor = Cursors.Default;
            }
        }